aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-10-03 17:38:19 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-10-03 17:38:19 -0700
commit4f2f867026315a33a30344a9cedc500568e9cb04 (patch)
tree2ce5753fd55eb8f7d310d3f4c9692accaa3004b7 /src
parent363ce16a8980f08b9c81fea4d51d3356cbad21a9 (diff)
socket listen faking
Diffstat (limited to 'src')
-rw-r--r--src/library.js28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/library.js b/src/library.js
index 72fb07e7..6c0a67a0 100644
--- a/src/library.js
+++ b/src/library.js
@@ -1209,7 +1209,7 @@ LibraryManager.library = {
return 0;
case {{{ cDefine('F_SETOWN') }}}:
case {{{ cDefine('F_GETOWN') }}}:
- // These are for sockets. We don't have them implemented (yet?).
+ // These are for sockets. We don't have them fully implemented yet.
___setErrNo(ERRNO_CODES.EINVAL);
return -1;
default:
@@ -6398,7 +6398,8 @@ LibraryManager.library = {
},
// ==========================================================================
- // sockets
+ // sockets. Note that the implementation assumes all sockets are always
+ // nonblocking
// ==========================================================================
$Sockets__deps: ['__setErrNo', '$ERRNO_CODES'],
@@ -6575,6 +6576,29 @@ LibraryManager.library = {
return 0;
},
+ bind__deps: ['connect'],
+ bind: function(fd, addr, addrlen) {
+ return _connect(fd, addr, addrlen);
+ },
+
+ listen: function(fd, backlog) {
+ return 0;
+ },
+
+ accept: function(fd, addr, addrlen) {
+ // TODO: webrtc queued incoming connections, etc.
+ // For now, the model is that bind does a connect, and we "accept" that one connection,
+ // which has host:port the same as ours. We also return the same socket fd.
+ var info = Sockets.fds[fd];
+ if (!info) return -1;
+ if (addr) {
+ setValue(addr + Sockets.sockaddr_in_layout.sin_addr, info.addr, 'i32');
+ setValue(addr + Sockets.sockaddr_in_layout.sin_port, info.port, 'i32');
+ setValue(addrlen, Sockets.sockaddr_in_layout.__size__, 'i32');
+ }
+ return fd;
+ },
+
// ==========================================================================
// emscripten.h
// ==========================================================================