Removed trans_comm.rs from the compiler. Updating aio/sio to work with the new chan and port system, started on a networking module for the standard library.

This commit is contained in:
Eric Holk 2011-08-15 16:54:02 -07:00
parent e33af7e0b5
commit cf2def46c1
34 changed files with 326 additions and 600 deletions

View file

@ -3,6 +3,7 @@
use std;
import std::unsafe::reinterpret_cast;
import std::task;
import std::comm;
fn test_nil() {
assert (() == ());
@ -60,20 +61,21 @@ fn test_box() {
}
fn test_port() {
let p1: port[int] = port();
let p2: port[int] = port();
let p1 = comm::mk_port[int]();
let p2 = comm::mk_port[int]();
assert p1 == p1;
assert p1 != p2;
}
fn test_chan() {
let p: port[int] = port();
let ch1 = chan(p);
let ch2 = chan(p);
let p: comm::_port[int] = comm::mk_port();
let ch1 = p.mk_chan();
let ch2 = p.mk_chan();
assert ch1 == ch1;
assert ch1 != ch2;
// Chans are equal because they are just task:port addresses.
assert ch1 == ch2;
}
fn test_ptr() {

View file

@ -1,16 +1,16 @@
// -*- rust -*-
use std;
import std::comm::mk_port;
import std::comm::send;
fn main() {
let po: port[int] = port();
let ch: chan[int] = chan(po);
ch <| 10;
let i: int;
po |> i;
let po = mk_port();
let ch = po.mk_chan();
send(ch, 10);
let i = po.recv();
assert (i == 10);
ch <| 11;
let j;
po |> j;
send(ch, 11);
let j = po.recv();
assert (j == 11);
}

View file

@ -1,5 +1,9 @@
// Sanity-check the code examples that appear in the object system
// documentation.
use std;
import std::comm::_chan;
import std::comm::send;
import std::comm::mk_port;
fn main() {
@ -43,9 +47,9 @@ fn main() {
}
}
obj sender(c: chan[int]) {
obj sender(c: _chan[int]) {
fn take(z: int) {
c <| z;
send(c, z);
}
}
@ -55,10 +59,10 @@ fn main() {
t.take(3);
}
let p: port[int] = port();
let p = mk_port[int]();
let t1: taker = adder(@mutable 0);
let t2: taker = sender(chan(p));
let t2: taker = sender(p.mk_chan());
give_ints(t1);
give_ints(t2);

View file

@ -1,5 +1,3 @@
// -*- rust -*-
// Regression tests for circular_buffer when using a unit
@ -7,7 +5,9 @@
use std;
import std::option;
import std::uint;
import std::comm;
import std::comm::mk_port;
import std::comm::send;
// A 12-byte unit to send over the channel
type record = {val1: u32, val2: u32, val3: u32};
@ -18,50 +18,52 @@ type record = {val1: u32, val2: u32, val3: u32};
// power of two so needs to be rounded up. Don't trigger any
// assertions.
fn test_init() {
let myport: port[record] = port();
let mychan = chan(myport);
let myport = mk_port[record]();
let mychan = myport.mk_chan();
let val: record = {val1: 0u32, val2: 0u32, val3: 0u32};
mychan <| val;
send(mychan, val);
}
// Dump lots of items into the channel so it has to grow.
// Don't trigger any assertions.
fn test_grow() {
let myport: port[record] = port();
let mychan = chan(myport);
let val: record = {val1: 0u32, val2: 0u32, val3: 0u32};
for each i: uint in uint::range(0u, 100u) { mychan <| val; }
let myport: comm::_port[record] = comm::mk_port();
let mychan = myport.mk_chan();
for each i: uint in uint::range(0u, 100u) {
let val: record = {val1: 0u32, val2: 0u32, val3: 0u32};
comm::send(mychan, val);
}
}
// Don't allow the buffer to shrink below it's original size
fn test_shrink1() {
let myport: port[i8] = port();
let mychan = chan(myport);
mychan <| 0i8;
let x;
myport |> x;
let myport = comm::mk_port[i8]();
let mychan = myport.mk_chan();
send(mychan, 0i8);
let x = myport.recv();
}
fn test_shrink2() {
let myport: port[record] = port();
let mychan = chan(myport);
let val: record = {val1: 0u32, val2: 0u32, val3: 0u32};
for each i: uint in uint::range(0u, 100u) { mychan <| val; }
for each i: uint in uint::range(0u, 100u) { let x; myport |> x; }
let myport = mk_port[record]();
let mychan = myport.mk_chan();
for each i: uint in uint::range(0u, 100u) {
let val: record = {val1: 0u32, val2: 0u32, val3: 0u32};
send(mychan, val);
}
for each i: uint in uint::range(0u, 100u) { let x = myport.recv(); }
}
// Test rotating the buffer when the unit size is not a power of two
fn test_rotate() {
let myport: port[record] = port();
let mychan = chan(myport);
for each i: uint in uint::range(0u, 100u) {
let myport = mk_port[record]();
let mychan = myport.mk_chan();
for each i: uint in uint::range(0u, 100u) {
let val = {val1: i as u32, val2: i as u32, val3: i as u32};
mychan <| val;
let x;
myport |> x;
send(mychan, val);
let x = myport.recv();
assert (x.val1 == i as u32);
assert (x.val2 == i as u32);
assert (x.val3 == i as u32);
@ -72,17 +74,16 @@ fn test_rotate() {
// Test rotating and growing the buffer when
// the unit size is not a power of two
fn test_rotate_grow() {
let myport: port[record] = port();
let mychan = chan(myport);
for each j: uint in uint::range(0u, 10u) {
for each i: uint in uint::range(0u, 10u) {
let myport = mk_port[record]();
let mychan = myport.mk_chan();
for each j: uint in uint::range(0u, 10u) {
for each i: uint in uint::range(0u, 10u) {
let val: record =
{val1: i as u32, val2: i as u32, val3: i as u32};
mychan <| val;
send(mychan, val);
}
for each i: uint in uint::range(0u, 10u) {
let x;
myport |> x;
for each i: uint in uint::range(0u, 10u) {
let x = myport.recv();
assert (x.val1 == i as u32);
assert (x.val2 == i as u32);
assert (x.val3 == i as u32);

View file

@ -1,8 +1,13 @@
use std;
import std::comm::_chan;
import std::comm::send;
import std::comm::mk_port;
// tests that ctrl's type gets inferred properly
type command[K, V] = {key: K, val: V};
fn cache_server[K, V](c: chan[chan[command[K, V]]]) {
let ctrl = port();
c <| chan(ctrl);
fn cache_server[K, V](c: _chan[_chan[command[K, V]]]) {
let ctrl = mk_port[_chan[command[K, V]]]();
send(c, ctrl.mk_chan());
}
fn main() { }

View file

@ -1,12 +1,12 @@
// xfail-stage1
// xfail-stage2
// xfail-stage3
use std;
import std::sio;
import std::task;
import std::net;
fn connectTask(cx: sio::ctx, ip: str, portnum: int) {
fn connectTask(cx: sio::ctx, ip: net::ip_addr, portnum: int) {
let client: sio::client;
client = sio::connect_to(cx, ip, portnum);
sio::close_client(client);
@ -14,10 +14,13 @@ fn connectTask(cx: sio::ctx, ip: str, portnum: int) {
fn main() {
let cx: sio::ctx = sio::new();
let srv: sio::server = sio::create_server(cx, "0.0.0.0", 9090);
let child: task = spawn connectTask(cx, "127.0.0.1", 9090);
let srv: sio::server = sio::create_server(cx,
net::parse_addr("0.0.0.0"), 9090);
let child = task::_spawn(bind connectTask(cx,
net::parse_addr("127.0.0.1"),
9090));
let client: sio::client = sio::accept_from(srv);
task::join(child);
task::join_id(child);
sio::close_client(client);
sio::close_server(srv);
sio::destroy(cx);

View file

@ -1,16 +1,15 @@
// -*- rust -*-
use std;
import std::comm;
// rustboot can't transmit nils across channels because they don't have
// any size, but rustc currently can because they do have size. Whether
// or not this is desirable I don't know, but here's a regression test.
fn main() {
let po: port[()] = port();
let ch: chan[()] = chan(po);
ch <| ();
let n: ();
po |> n;
let po: comm::_port[()] = comm::mk_port();
let ch: comm::_chan[()] = po.mk_chan();
comm::send(ch, ());
let n: () = po.recv();
assert (n == ());
}

View file

@ -1,15 +1,15 @@
use std;
import std::comm::mk_port;
import std::comm::send;
/*
This is about the simplest program that can successfully send a
message.
*/
fn main() {
let po: port[int] = port();
let ch: chan[int] = chan(po);
ch <| 42;
let r;
po |> r;
let po = mk_port[int]();
let ch = po.mk_chan();
send(ch, 42);
let r = po.recv();
log_err r;
}