assert(true, "running server");
// set up listeners
- assert(t4 = net.tcpListen("localhost", 1024), "listening on ip4/tcp");
- assert(t6 = net.tcp6Listen("localhost", 1024), "listening on ip6/tcp");
- assert(u4 = net.udpListen("localhost", 1024), "listening on ip4/udp");
- assert(u6 = net.udp6Listen("localhost", 1024), "listening on ip6/udp");
- assert(ux = net.unixListen(xsock), "listening on unix/" + xsock);
+ assert(t4 = new net.Socket("tcp" ).listen("localhost", 1024), "listening on ip4/tcp");
+ assert(t6 = new net.Socket("tcp6").listen("localhost", 1024), "listening on ip6/tcp");
+ assert(u4 = new net.Socket("udp" ).listen("localhost", 1024), "listening on ip4/udp");
+ assert(u6 = new net.Socket("udp6").listen("localhost", 1024), "listening on ip6/udp");
+ assert(ux = new net.Socket("unix").listen(xsock), "listening on unix:" + xsock);
std.printf("\n")
// check socket props
// launch client
new os.Worker(scriptArgs[0]);
+ // if (!net.fork()) client();
// accept connections
assert(ct4 = t4.accept(), "received connection on ip4/tcp (by "+ct4.peerName+"/"+ct4.peerPort+")");
assert(true, "running client");
var t4, t6, u4, u6, ux, sock;
- // test global timeout setting
- assert(! net.getTimeout(), "default connect timeout unset");
- net.setTimeout(1);
- assert(net.getTimeout() == 1, "set default connect timeout");
+
+ t4 = new net.Socket("tcp" );
+ t6 = new net.Socket("tcp6");
+ u4 = new net.Socket("udp" );
+ u6 = new net.Socket("udp6");
+ ux = new net.Socket("unix");
+
+ // test default timeout setting
+ for (sock of [t4, t6, u4, u6, ux]) {
+ assert(! sock.timeout, "default connect timeout unset");
+ sock.timeout = 1;
+ assert(sock.timeout == 1, "set default connect timeout");
+ }
// test failing connections
- try { t4 = net.tcpConnect( "localhost", 1); } catch(e) {}
- assert(!t4, "conrefused for ip4/tcp");
- try { t6 = net.tcp6Connect("localhost", 1); } catch(e) {}
- assert(!t6, "conrefused for ip6/tcp");
- try { ux = net.unixConnect("/nonexist"); } catch(e) {}
- assert(!ux, "conrefused for unix");
+ try { t4.connect( "localhost", 1); } catch(e) {
+ assert(!t4.connected, "conrefused for ip4/tcp");
+ }
+ try { t6.connect("localhost", 1); } catch(e) {
+ assert(!t6.connected, "conrefused for ip6/tcp");
+ }
+ try { ux.connect("/nonexist"); } catch(e) {
+ assert(!ux.connected, "conrefused for unix");
+ }
// test connection state property
- assert(t4 = net.tcpConnect("localhost", 1024), "connected to ip4/tcp");
- assert(t6 = net.tcp6Connect("localhost", 1024), "connected to ip6/tcp");
- assert(u4 = net.udpConnect("localhost", 1024), "connected to ip4/udp");
- assert(u6 = net.udp6Connect("localhost", 1024), "connected to ip6/udp");
- assert(ux = net.unixConnect(xsock), "connected to unix");
+ assert(t4.connect("localhost", 1024), "connected to ip4/tcp");
+ assert(t6.connect("localhost", 1024), "connected to ip6/tcp");
+ assert(u4.connect("localhost", 1024), "connected to ip4/udp");
+ assert(u6.connect("localhost", 1024), "connected to ip6/udp");
+ assert(ux.connect(xsock), "connected to unix");
// send "ketchup", receive "mayo"
for ( sock of [t4, t6, ux, u4, u6] ) {
// set up new udp connections, test destination option in udp send, send "mustard"
assert(!u4.close(), "closed ip4/udp client");
assert(!u6.close(), "closed ip6/udp client");
- assert(u4 = net.udpConnect("localhost", 1025), "connected to ip4/udp");
- assert(u6 = net.udp6Connect("localhost", 1025), "connected to ip6/udp");
+ assert(u4 = new net.Socket("udp").connect("localhost", 1025), "connected to ip4/udp");
+ assert(u6 = new net.Socket("udp6").connect("localhost", 1025), "connected to ip6/udp");
assert(u4.send("mustard", "localhost", 1024), "send string from different ip4/udp connection")
assert(u6.send("mustard", "localhost", 1024), "send string from different ip6/udp connection")
}
if (os.Worker.parent) {
- // test global timeout setting
+ // test default timeout setting
// test failing connections
// test connection state property
// send "ketchup", receive "mayo"