diff server_socket.cpp @ 43:cdfbd4b71027

Added listen() method to ServerSocket().
author Atul Varma <varmaa@toolness.com>
date Wed, 24 Jun 2009 14:12:59 -0700
parents 68d2a675a33a
children 1fd58132b533
line wrap: on
line diff
--- a/server_socket.cpp	Wed Jun 24 14:05:32 2009 -0700
+++ b/server_socket.cpp	Wed Jun 24 14:12:59 2009 -0700
@@ -85,6 +85,29 @@
   JSCLASS_NO_RESERVED_MEMBERS
 };
 
+JSBool listen(JSContext *cx, JSObject *obj, uintN argc,
+              jsval *argv, jsval *rval)
+{
+  PRInt32 backlog;
+
+  if (!JS_ConvertArguments(cx, argc, argv, "i", &backlog))
+    return JS_FALSE;
+
+  PRFileDesc *fd;
+  if (!getSocket(cx, obj, &fd))
+    return JS_FALSE;
+
+  PRStatus result = PR_Listen(fd, backlog);
+
+  if (result != PR_SUCCESS) {
+    JS_ReportError(cx, "Listen failed.");
+    return JS_FALSE;
+  }
+
+  *rval = JSVAL_VOID;
+  return JS_TRUE;
+}
+
 JSBool bind(JSContext *cx, JSObject *obj, uintN argc,
             jsval *argv, jsval *rval)
 {
@@ -119,7 +142,8 @@
 }
 
 static JSFunctionSpec methods[] = {
-  JS_FS("bind",          bind,        1, 0, 0),
+  JS_FS("bind",          bind,        2, 0, 0),
+  JS_FS("listen",        listen,      1, 0, 0),
   JS_FS_END
 };