diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-10-03 18:30:18 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-10-03 18:30:18 -0700 |
commit | 4a5d3521d7f72b8aded5d2bddd74d5541d1eff3f (patch) | |
tree | 41f6c0d8b359b525188d65cdd6a11ea65ce7d795 | |
parent | 7cf5981aa742f9e031a5c5e6d45486d2eed0b66d (diff) |
socket debugging
-rw-r--r-- | src/library.js | 27 | ||||
-rw-r--r-- | tests/enet_client.c | 3 | ||||
-rw-r--r-- | tests/enet_server.c | 1 | ||||
-rwxr-xr-x | tests/runner.py | 2 |
4 files changed, 30 insertions, 3 deletions
diff --git a/src/library.js b/src/library.js index 261b4687..221da010 100644 --- a/src/library.js +++ b/src/library.js @@ -6456,14 +6456,27 @@ LibraryManager.library = { info.bufferWrite = info.bufferRead = 0; info.socket.onmessage = function (event) { var data = event.data; +#if SOCKET_DEBUG + Module.print(['onmessage', window.location, event.data, window.atob(data)]); +#endif if (typeof data == 'string') { var binaryString = window.atob(data); var len = binaryString.length; +#if SOCKET_DEBUG + var out = []; +#endif for (var i = 0; i < len; i++) { - info.buffer[info.bufferWrite++] = binaryString.charCodeAt(i); + var curr = binaryString.charCodeAt(i); + info.buffer[info.bufferWrite++] = curr; +#if SOCKET_DEBUG + out.push(curr); +#endif if (info.bufferWrite == Sockets.BUFFER_SIZE) info.bufferWrite = 0; if (info.bufferWrite == info.bufferRead) throw 'socket buffer overflow'; } +#if SOCKET_DEBUG + Module.print(['onmessage data:', out]); +#endif } else { console.log('binary!'); } @@ -6509,6 +6522,9 @@ LibraryManager.library = { len--; ret++; } +#if SOCKET_DEBUG + Module.print('recv: ' + Array.prototype.slice.call(HEAPU8.subarray(buf-len, buf))); +#endif return ret; }, @@ -6516,6 +6532,9 @@ LibraryManager.library = { send: function(fd, buf, len, flags) { var info = Sockets.fds[fd]; if (!info) return -1; +#if SOCKET_DEBUG + Module.print('send: ' + Array.prototype.slice.call(HEAPU8.subarray(buf, buf+len))); +#endif info.sender(Pointer_stringify(buf, len)); return len; }, @@ -6535,7 +6554,11 @@ LibraryManager.library = { for (var i = 0; i < num; i++) { var currNum = {{{ makeGetValue('msg', 'Sockets.msghdr_layout.msg_iov+8*i' + '+4', 'i32') }}}; if (!currNum) continue; - data += Pointer_stringify({{{ makeGetValue('msg', 'Sockets.msghdr_layout.msg_iov+8*i', 'i8*') }}}, currNum); + 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))); +#endif + data += Pointer_stringify(currBuf, currNum); } info.sender(data); return data.length; diff --git a/tests/enet_client.c b/tests/enet_client.c index bc4d8ba7..f3101306 100644 --- a/tests/enet_client.c +++ b/tests/enet_client.c @@ -28,6 +28,7 @@ void main_loop() { /* Reset the peer's client information. */ event.peer -> data = NULL; enet_host_destroy(host); + break; default: printf("whaaa? %d\n", event.type); } @@ -79,6 +80,8 @@ int main (int argc, char ** argv) emscripten_run_script("console.log('adding iframe');" "var iframe = document.createElement('iframe');" "iframe.src = 'server.html';" + "iframe.width = '100%';" + "iframe.height = '25%';" "document.body.appendChild(iframe);" "console.log('added.');"); #endif diff --git a/tests/enet_server.c b/tests/enet_server.c index b19366f5..52eed3e8 100644 --- a/tests/enet_server.c +++ b/tests/enet_server.c @@ -53,6 +53,7 @@ void main_loop() { /* Reset the peer's client information. */ event.peer -> data = NULL; enet_host_destroy(host); + break; default: printf("whaaa? %d\n", event.type); } diff --git a/tests/runner.py b/tests/runner.py index 9608f24d..28d59f21 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -8758,7 +8758,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) + print >> sys.stderr, 'running websockify on %d, forward to tcp %d' % (self.port+1, self.port) 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() |