rust/src/test/run-pass/issue-687.rs

56 lines
1.4 KiB
Rust
Raw Normal View History

use std;
2011-08-15 18:38:23 -05:00
import std::vec;
import std::task;
import std::comm;
import std::comm::chan;
import std::comm::port;
import std::comm::recv;
import std::comm::send;
tag msg { closed; received([u8]); }
2011-10-20 22:34:04 -05:00
fn producer(c: chan<[u8]>) {
send(c, [1u8, 2u8, 3u8, 4u8]);
let empty: [u8] = [];
send(c, empty);
}
2011-10-20 22:34:04 -05:00
fn packager(&&args: (chan<chan<[u8]>>, chan<msg>)) {
let (cb, msg) = args;
let p: port<[u8]> = port();
send(cb, chan(p));
2011-07-27 07:19:39 -05:00
while true {
log "waiting for bytes";
let data = recv(p);
log "got bytes";
if vec::len(data) == 0u { log "got empty bytes, quitting"; break; }
log "sending non-empty buffer of length";
2011-08-15 18:38:23 -05:00
log vec::len(data);
send(msg, received(data));
log "sent non-empty buffer";
}
log "sending closed message";
send(msg, closed);
log "sent closed message";
}
fn main() {
let p: port<msg> = port();
let recv_reader: port<chan<[u8]>> = port();
let pack = task::spawn((chan(recv_reader), chan(p)), packager);
2011-07-27 07:19:39 -05:00
let source_chan: chan<[u8]> = recv(recv_reader);
let prod = task::spawn(source_chan, producer);
2011-07-27 07:19:39 -05:00
while true {
let msg = recv(p);
2011-07-27 07:19:39 -05:00
alt msg {
closed. { log "Got close message"; break; }
received(data) {
log "Got data. Length is:";
log vec::len::<u8>(data);
2011-07-27 07:19:39 -05:00
}
}
}
}