socket debugging
This commit is contained in:
Родитель
7cf5981aa7
Коммит
4a5d3521d7
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
Загрузка…
Ссылка в новой задаче