Browse Source

add echo test. remove debug printfs

v0.7.4-release
Ryan 16 years ago
parent
commit
63ec0454d2
  1. 2
      src/net.cc
  2. 49
      test/test-echoServer.js

2
src/net.cc

@ -181,8 +181,6 @@ Server::OnConnection (oi_server *s, struct sockaddr *remote_addr, socklen_t remo
Server *server = static_cast<Server*> (s->data);
HandleScope scope;
printf("DEBUG: got connection\n");
Local<Object> socket_handle = socket_template->GetFunction()->NewInstance();
Socket *socket = new Socket(socket_handle, 60.0);
socket->handle_->Delete(String::NewSymbol("connectTCP"));

49
test/test-echoServer.js

@ -0,0 +1,49 @@
include("mjsunit");
function onLoad() {
server = new Server(1024);
puts("listening at port 12123")
server.listenTCP(12123, function (connection) {
puts("got connection.");
connection.onRead = function (data) {
if (data === null) {
server.close();
connection.close();
return;
}
puts ("server read: " + data.toString());
if (/QUIT/.exec(data)) {
server.close();
connection.close();
} else if (/PING/.exec(data)) {
connection.write("PONG");
}
}
});
socket = new Socket;
var count = 0;
socket.onRead = function (data) {
puts ("client read: " + data.toString());
assertEquals("PONG", data);
setTimeout(function() {
count += 1;
if (count < 10) {
socket.write("PING");
} else {
socket.write("QUIT\n");
socket.close();
}
}, 100);
};
socket.onClose = function () {
assertEquals(10, count);
}
socket.connectTCP(12123, "localhost", function (status) {
if(status != 0)
process.exit(1);
socket.write("PING");
});
}
Loading…
Cancel
Save