diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-10-02 18:41:28 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-10-02 18:41:28 -0700 |
commit | cc14e2ad3a8764b3ee56fee0a7a71dc5be3de5ec (patch) | |
tree | e22b5482986e0dcf6d88bf4b30bb6a05f91dfaf5 | |
parent | a607486fb03f328927230958d850d4832c15a77e (diff) |
enet and socket improvements
-rw-r--r-- | src/library.js | 1 | ||||
-rw-r--r-- | tests/enet_client.c | 5 | ||||
-rw-r--r-- | tests/enet_server.c | 5 | ||||
-rwxr-xr-x | tests/runner.py | 22 |
4 files changed, 18 insertions, 15 deletions
diff --git a/src/library.js b/src/library.js index 546224d4..7757bf75 100644 --- a/src/library.js +++ b/src/library.js @@ -6446,6 +6446,7 @@ LibraryManager.library = { info.host = _gethostbyname.table[low + 0xff*high]; assert(info.host, 'problem translating fake ip ' + parts); } + console.log('opening ws://' + info.host + ':' + info.port); info.socket = new WebSocket('ws://' + info.host + ':' + info.port, ['arraybuffer']); info.socket.binaryType = 'arraybuffer'; info.buffer = new Uint8Array(Sockets.BUFFER_SIZE); diff --git a/tests/enet_client.c b/tests/enet_client.c index b22e7bc4..bc4d8ba7 100644 --- a/tests/enet_client.c +++ b/tests/enet_client.c @@ -6,9 +6,8 @@ ENetHost * host; void main_loop() { - printf("loop!\n"); ENetEvent event; - if (enet_host_service (host, & event, 1000) == 0) return; + if (enet_host_service (host, & event, 0) == 0) return; switch (event.type) { case ENET_EVENT_TYPE_CONNECT: @@ -84,7 +83,7 @@ int main (int argc, char ** argv) "console.log('added.');"); #endif - emscripten_set_main_loop(main_loop, 0); + emscripten_set_main_loop(main_loop, 500); return 1; } diff --git a/tests/enet_server.c b/tests/enet_server.c index 8aceda22..b19366f5 100644 --- a/tests/enet_server.c +++ b/tests/enet_server.c @@ -25,9 +25,8 @@ void send_msg(ENetPeer *peer) { } void main_loop() { - printf("loop!\n"); ENetEvent event; - if (enet_host_service (host, & event, 500) == 0) return; + if (enet_host_service (host, & event, 0) == 0) return; switch (event.type) { case ENET_EVENT_TYPE_CONNECT: @@ -84,7 +83,7 @@ int main (int argc, char ** argv) exit (EXIT_FAILURE); } - emscripten_set_main_loop(main_loop, 0); + emscripten_set_main_loop(main_loop, 500); return 1; } diff --git a/tests/runner.py b/tests/runner.py index 209ab6e7..41a62d37 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -8720,6 +8720,7 @@ elif 'browser' in str(sys.argv): print '[kill succeeded]' except: print '[kill fail]' + browser.pids_to_clean = [] # Runs a websocket server at a specific port. port is the true tcp socket we forward to, port+1 is the websocket one class WebsockHarness: @@ -8749,6 +8750,7 @@ elif 'browser' in str(sys.argv): print '[Socket server on processes %s]' % str(browser.pids_to_clean[-2:]) def websockify_func(q): + print >> sys.stderr, 'running websockify on tcp %d, ws %d' % (self.port, self.port+1) proc = Popen([path_from_root('third_party', 'websockify', 'other', 'websockify'), '-vvv', str(self.port+1), '127.0.0.1:' + str(self.port)]) q.put(proc.pid) proc.communicate() @@ -8778,6 +8780,7 @@ elif 'browser' in str(sys.argv): def make_relay_server(self, port1, port2): def relay_server(q): + print >> sys.stderr, 'creating relay server on ports %d,%d' % (port1, port2) proc = Popen(['python', path_from_root('tests', 'socket_relay.py'), str(port1), str(port2)]) q.put(proc.pid) proc.communicate() @@ -8800,18 +8803,19 @@ elif 'browser' in str(sys.argv): self.clean_pids() def zzztest_zz_enet(self): + try_delete(self.in_dir('enet')) + shutil.copytree(path_from_root('tests', 'enet'), self.in_dir('enet')) + pwd = os.getcwd() + os.chdir(self.in_dir('enet')) + Popen(['python', path_from_root('emconfigure'), './configure']).communicate() + Popen(['python', path_from_root('emmake'), 'make']).communicate() + enet = [self.in_dir('enet', '.libs', 'libenet.a'), '-I'+path_from_root('tests', 'enet', 'include')] + os.chdir(pwd) + Popen(['python', EMCC, path_from_root('tests', 'enet_server.c'), '-o', 'server.html'] + enet).communicate() + try: with self.WebsockHarness(1234, self.make_relay_server(1234, 1236)): with self.WebsockHarness(1236, no_server=True): - try_delete(self.in_dir('enet')) - shutil.copytree(path_from_root('tests', 'enet'), self.in_dir('enet')) - pwd = os.getcwd() - os.chdir(self.in_dir('enet')) - Popen(['python', path_from_root('emconfigure'), './configure']).communicate() - Popen(['python', path_from_root('emmake'), 'make']).communicate() - enet = [self.in_dir('enet', '.libs', 'libenet.a'), '-I'+path_from_root('tests', 'enet', 'include')] - os.chdir(pwd) - Popen(['python', EMCC, path_from_root('tests', 'enet_server.c'), '-o', 'server.html'] + enet).communicate() self.btest('enet_client.c', expected='cheez', args=enet) finally: self.clean_pids() |