diff options
-rw-r--r-- | src/library.js | 58 | ||||
-rw-r--r-- | src/settings.js | 1 | ||||
-rw-r--r-- | tests/enet_client.c | 12 | ||||
-rw-r--r-- | tests/enet_server.c | 10 | ||||
-rwxr-xr-x | tests/runner.py | 4 |
5 files changed, 75 insertions, 10 deletions
diff --git a/src/library.js b/src/library.js index 221da010..6662e9b7 100644 --- a/src/library.js +++ b/src/library.js @@ -6475,7 +6475,7 @@ LibraryManager.library = { if (info.bufferWrite == info.bufferRead) throw 'socket buffer overflow'; } #if SOCKET_DEBUG - Module.print(['onmessage data:', out]); + Module.print(['onmessage data:', len, ':', out]); #endif } else { console.log('binary!'); @@ -6515,6 +6515,9 @@ LibraryManager.library = { return 0; // should this be -1 like the spec says? } var ret = 0; +#if SOCKET_DEBUG + Module.print('pre-recv: ' + [len, info.bufferWrite, info.bufferRead]); +#endif while (info.bufferWrite != info.bufferRead && len > 0) { // write out a byte {{{ makeSetValue('buf++', '0', 'info.buffer[info.bufferRead++]', 'i8') }}}; @@ -6523,7 +6526,7 @@ LibraryManager.library = { ret++; } #if SOCKET_DEBUG - Module.print('recv: ' + Array.prototype.slice.call(HEAPU8.subarray(buf-len, buf))); + Module.print('recv: ' + ret + ' : ' + Array.prototype.slice.call(HEAPU8.subarray(buf-len, buf))); #endif return ret; }, @@ -6556,7 +6559,7 @@ LibraryManager.library = { if (!currNum) continue; var currBuf = {{{ makeGetValue('msg', 'Sockets.msghdr_layout.msg_iov+8*i', 'i8*') }}}; #if SOCKET_DEBUG - Module.print('sendmsg part ' + i + ' : ' + Array.prototype.slice.call(HEAPU8.subarray(currBuf, currBuf+currNum))); + Module.print('sendmsg part ' + i + ' : ' + currNum + ' : ' + Array.prototype.slice.call(HEAPU8.subarray(currBuf, currBuf+currNum))); #endif data += Pointer_stringify(currBuf, currNum); } @@ -6564,8 +6567,53 @@ LibraryManager.library = { return data.length; }, - recvmsg__deps: ['$Sockets', 'connect', 'recv'], - recvmsg: function(fd, buf, len, flags, addr, addrlen) { + recvmsg__deps: ['$Sockets', 'connect', 'recv', '__setErrNo', '$ERRNO_CODES'], + recvmsg: function(fd, msg, flags) { +#if SOCKET_DEBUG + Module.print('recvmsg!'); +#endif + var info = Sockets.fds[fd]; + if (!info) return -1; + // if we are not connected, use the address info in the message + if (!info.connected) { +#if SOCKET_DEBUG + Module.print('recvmsg connecting'); +#endif + var name = {{{ makeGetValue('msg', 'Sockets.msghdr_layout.msg_name', '*') }}}; + assert(name, 'sendmsg on non-connected socket, and no name/address in the message'); + _connect(fd, name, {{{ makeGetValue('msg', 'Sockets.msghdr_layout.msg_namelen', 'i32') }}}); + } + var bytes = info.bufferWrite - info.bufferRead; + if (bytes < 0) bytes += Sockets.BUFFER_SIZE; +#if SOCKET_DEBUG + Module.print('recvmsg bytes: ' + bytes); +#endif + if (bytes == 0) { + ___setErrNo(ERRNO_CODES.EWOULDBLOCK); + return -1; + } + var ret = bytes; + var num = {{{ makeGetValue('msg', 'Sockets.msghdr_layout.msg_iovlen', 'i32') }}}; + var data = ''; + for (var i = 0; i < num && bytes > 0; i++) { + var currNum = {{{ makeGetValue('msg', 'Sockets.msghdr_layout.msg_iov+8*i' + '+4', 'i32') }}}; +#if SOCKET_DEBUG + Module.print('recvmsg loop ' + [i, num, bytes, currNum]); +#endif + if (!currNum) continue; + currNum = Math.min(currNum, bytes); // XXX what should happen when we partially fill a buffer..? + bytes -= currNum; + var currBuf = {{{ makeGetValue('msg', 'Sockets.msghdr_layout.msg_iov+8*i', 'i8*') }}}; +#if SOCKET_DEBUG + Module.print('recvmsg call recv ' + currNum); +#endif + assert(_recv(fd, currBuf, currNum, 0) == currNum); + } + return ret; + }, + + recvfrom__deps: ['$Sockets', 'connect', 'recv'], + recvfrom: function(fd, buf, len, flags, addr, addrlen) { var info = Sockets.fds[fd]; if (!info) return -1; // if we are not connected, use the address info in the message diff --git a/src/settings.js b/src/settings.js index 5970737c..9e6f257a 100644 --- a/src/settings.js +++ b/src/settings.js @@ -124,6 +124,7 @@ var LIBRARY_DEBUG = 0; // Print out when we enter a library call (library*.js). // emscripten_run_script("Runtime.debug = ...;"); var GL_DEBUG = 0; // Print out all calls into WebGL. As with LIBRARY_DEBUG, you can set a runtime // option, in this case GL.debug. +var SOCKET_DEBUG = 0; // Log out socket/network data transfer. var PROFILE_MAIN_LOOP = 0; // Profile the function called in set_main_loop diff --git a/tests/enet_client.c b/tests/enet_client.c index f3101306..6eb088a3 100644 --- a/tests/enet_client.c +++ b/tests/enet_client.c @@ -6,6 +6,14 @@ ENetHost * host; void main_loop() { + static int counter = 0; + counter++; + if (counter == 20) { + printf("stop!\n"); + emscripten_cancel_main_loop(); + return; + } + ENetEvent event; if (enet_host_service (host, & event, 0) == 0) return; switch (event.type) @@ -81,12 +89,12 @@ int main (int argc, char ** argv) "var iframe = document.createElement('iframe');" "iframe.src = 'server.html';" "iframe.width = '100%';" - "iframe.height = '25%';" + "iframe.height = '33%';" "document.body.appendChild(iframe);" "console.log('added.');"); #endif - emscripten_set_main_loop(main_loop, 500); + emscripten_set_main_loop(main_loop, 1); return 1; } diff --git a/tests/enet_server.c b/tests/enet_server.c index 52eed3e8..f43d511d 100644 --- a/tests/enet_server.c +++ b/tests/enet_server.c @@ -25,6 +25,14 @@ void send_msg(ENetPeer *peer) { } void main_loop() { + static int counter = 0; + counter++; + if (counter == 20) { + printf("stop!\n"); + emscripten_cancel_main_loop(); + return; + } + ENetEvent event; if (enet_host_service (host, & event, 0) == 0) return; switch (event.type) @@ -84,7 +92,7 @@ int main (int argc, char ** argv) exit (EXIT_FAILURE); } - emscripten_set_main_loop(main_loop, 500); + emscripten_set_main_loop(main_loop, 1); return 1; } diff --git a/tests/runner.py b/tests/runner.py index 28d59f21..dc2dab6a 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -8828,12 +8828,12 @@ elif 'browser' in str(sys.argv): 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() + Popen(['python', EMCC, path_from_root('tests', 'enet_server.c'), '-o', 'server.html', '-s', 'SOCKET_DEBUG=1'] + enet).communicate() try: with self.WebsockHarness(1234, self.make_relay_server(1234, 1236)): with self.WebsockHarness(1236, no_server=True): - self.btest('enet_client.c', expected='cheez', args=enet) + self.btest('enet_client.c', expected='cheez', args=enet+['-s', 'SOCKET_DEBUG=1']) finally: self.clean_pids() |