Mercurial > spidermonkey-playground
changeset 44:1fd58132b533
added accept() method with a big TODO.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Wed, 24 Jun 2009 14:22:42 -0700 |
parents | cdfbd4b71027 |
children | 0aac2efec58e |
files | server_socket.cpp tcb.js |
diffstat | 2 files changed, 29 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/server_socket.cpp Wed Jun 24 14:12:59 2009 -0700 +++ b/server_socket.cpp Wed Jun 24 14:22:42 2009 -0700 @@ -90,7 +90,7 @@ { PRInt32 backlog; - if (!JS_ConvertArguments(cx, argc, argv, "i", &backlog)) + if (!JS_ConvertArguments(cx, argc, argv, "/i", &backlog)) return JS_FALSE; PRFileDesc *fd; @@ -108,6 +108,30 @@ return JS_TRUE; } +JSBool accept(JSContext *cx, JSObject *obj, uintN argc, + jsval *argv, jsval *rval) +{ + PRIntervalTime timeout = PR_INTERVAL_NO_TIMEOUT; + + if (!JS_ConvertArguments(cx, argc, argv, "/i", &timeout)) + return JS_FALSE; + + PRFileDesc *fd; + if (!getSocket(cx, obj, &fd)) + return JS_FALSE; + + PRNetAddr addr; + PRFileDesc *conn = PR_Accept(fd, &addr, timeout); + + *rval = JSVAL_NULL; + if (conn != NULL) { + JS_ReportError(cx, "TODO: Make a new socket object for the connection!"); + return JS_FALSE; + } + + return JS_TRUE; +} + JSBool bind(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { @@ -143,7 +167,8 @@ static JSFunctionSpec methods[] = { JS_FS("bind", bind, 2, 0, 0), - JS_FS("listen", listen, 1, 0, 0), + JS_FS("listen", listen, 0, 0, 0), + JS_FS("accept", accept, 0, 0, 0), JS_FS_END };