Skip to content
Snippets Groups Projects
Commit c3c30e30 authored by rswindell's avatar rswindell
Browse files

Created poll() method - with optional timeout argument (in seconds).

parent 6d93705c
No related branches found
No related tags found
No related merge requests found
......@@ -513,6 +513,30 @@ js_ioctlsocket(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rva
return(JS_TRUE);
}
static JSBool
js_poll(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
private_t* p;
fd_set socket_set;
struct timeval tv = {0, 0};
if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL)
return(JS_FALSE);
if(argc>0)
tv.tv_sec = JSVAL_TO_INT(argv[0]);
FD_ZERO(&socket_set);
FD_SET(p->sock,&socket_set);
*rval = INT_TO_JSVAL(select(p->sock+1,&socket_set,NULL,NULL,&tv));
p->last_error=ERROR_VALUE;
return(JS_TRUE);
}
/* Socket Object Properites */
enum {
SOCK_PROP_LAST_ERROR
......@@ -655,6 +679,7 @@ static JSFunctionSpec js_socket_functions[] = {
{"getoption", js_getsockopt, 1}, /* getsockopt(opt) */
{"setoption", js_setsockopt, 2}, /* setsockopt(opt,val) */
{"ioctl", js_ioctlsocket, 1}, /* ioctl(cmd,arg) */
{"poll", js_poll, 1}, /* poll(seconds) */
{0}
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment