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

Created a Socket.option_list: an array of option names supported by the current

platform and socket type combination.
parent 8620f4d9
No related branches found
No related tags found
No related merge requests found
...@@ -1301,6 +1301,33 @@ static jsSyncMethodSpec js_socket_functions[] = { ...@@ -1301,6 +1301,33 @@ static jsSyncMethodSpec js_socket_functions[] = {
{0} {0}
}; };
static BOOL js_DefineSocketOptionsArray(JSContext *cx, JSObject *obj, int type)
{
size_t i;
size_t count=0;
jsval val;
JSObject* array;
socket_option_t* options;
if((options=getSocketOptionList())==NULL)
return(FALSE);
if((array=JS_NewArrayObject(cx, 0, NULL))==NULL)
return(FALSE);
if(!JS_DefineProperty(cx, obj, "option_list", OBJECT_TO_JSVAL(array)
, NULL, NULL, JSPROP_ENUMERATE))
return(FALSE);
for(i=0; options[i].name!=NULL; i++) {
if(options[i].type && options[i].type!=type)
continue;
val=STRING_TO_JSVAL(JS_NewStringCopyZ(cx,options[i].name));
JS_SetElement(cx, array, count++, &val);
}
return(TRUE);
}
/* Socket Constructor (creates socket descriptor) */ /* Socket Constructor (creates socket descriptor) */
static JSBool static JSBool
...@@ -1341,6 +1368,9 @@ js_socket_constructor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsv ...@@ -1341,6 +1368,9 @@ js_socket_constructor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsv
return(JS_FALSE); return(JS_FALSE);
} }
if(!js_DefineSocketOptionsArray(cx, obj, type))
return(JS_FALSE);
if(!js_DefineSyncMethods(cx, obj, js_socket_functions, FALSE)) { if(!js_DefineSyncMethods(cx, obj, js_socket_functions, FALSE)) {
JS_ReportError(cx,"js_DefineSyncMethods failed"); JS_ReportError(cx,"js_DefineSyncMethods failed");
return(JS_FALSE); return(JS_FALSE);
...@@ -1375,8 +1405,10 @@ JSObject* DLLCALL js_CreateSocketClass(JSContext* cx, JSObject* parent) ...@@ -1375,8 +1405,10 @@ JSObject* DLLCALL js_CreateSocketClass(JSContext* cx, JSObject* parent)
JSObject* DLLCALL js_CreateSocketObject(JSContext* cx, JSObject* parent, char *name, SOCKET sock) JSObject* DLLCALL js_CreateSocketObject(JSContext* cx, JSObject* parent, char *name, SOCKET sock)
{ {
JSObject* obj; JSObject* obj;
private_t* p; private_t* p;
int type=SOCK_STREAM;
socklen_t len;
obj = JS_DefineObject(cx, parent, name, &js_socket_class, NULL obj = JS_DefineObject(cx, parent, name, &js_socket_class, NULL
,JSPROP_ENUMERATE|JSPROP_READONLY); ,JSPROP_ENUMERATE|JSPROP_READONLY);
...@@ -1387,6 +1419,12 @@ JSObject* DLLCALL js_CreateSocketObject(JSContext* cx, JSObject* parent, char *n ...@@ -1387,6 +1419,12 @@ JSObject* DLLCALL js_CreateSocketObject(JSContext* cx, JSObject* parent, char *n
if(!js_DefineSyncProperties(cx, obj, js_socket_properties)) if(!js_DefineSyncProperties(cx, obj, js_socket_properties))
return(NULL); return(NULL);
len = sizeof(type);
getsockopt(sock,SOL_SOCKET,SO_TYPE,(void*)&type,&len);
if(!js_DefineSocketOptionsArray(cx, obj, type))
return(NULL);
if((p=(private_t*)malloc(sizeof(private_t)))==NULL) if((p=(private_t*)malloc(sizeof(private_t)))==NULL)
return(NULL); return(NULL);
memset(p,0,sizeof(private_t)); memset(p,0,sizeof(private_t));
......
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