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

56 lines
1.3 KiB
Rust
Raw Normal View History

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