From a1ca4654310204d536da1b3e0fe6e6a6e4483ce7 Mon Sep 17 00:00:00 2001
From: rswindell <>
Date: Mon, 11 Jun 2007 21:17:57 +0000
Subject: [PATCH] Fix for socket_select(), don't log errno using lprintf() if
 select returns an error  - this is the wrong error value for Windows and it
 shouldn't be logged using lprintf (to the Telnet log/window). Instead, this
 JS function will now return null if/when select returns < 0 and the script
 can handle the error condition and log or not log as it sees fit.

---
 src/sbbs3/js_global.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/sbbs3/js_global.c b/src/sbbs3/js_global.c
index 0e1a759dcc..91e65e82ad 100644
--- a/src/sbbs3/js_global.c
+++ b/src/sbbs3/js_global.c
@@ -8,7 +8,7 @@
  * @format.tab-size 4		(Plain Text/Source Code File Header)			*
  * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
  *																			*
- * Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html		*
+ * Copyright 2007 Rob Swindell - http://www.synchro.net/copyright.html		*
  *																			*
  * This program is free software; you can redistribute it and/or			*
  * modify it under the terms of the GNU General Public License				*
@@ -2855,18 +2855,18 @@ js_socket_select(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *r
 		}
     }
 
-	if(select(maxsock+1,rd_set,wr_set,NULL,&tv)<0)
-		lprintf(LOG_DEBUG,"Error in socket_select()  %s (%d)",strerror(errno),errno);
+	if(select(maxsock+1,rd_set,wr_set,NULL,&tv) >= 0) {
 
-	for(i=0;i<limit;i++) {
-		if(index[i]!=INVALID_SOCKET && FD_ISSET(index[i],&socket_set)) {
-			val=INT_TO_JSVAL(i);
-   			if(!JS_SetElement(cx, rarray, len++, &val))
-				break;
+		for(i=0;i<limit;i++) {
+			if(index[i]!=INVALID_SOCKET && FD_ISSET(index[i],&socket_set)) {
+				val=INT_TO_JSVAL(i);
+   				if(!JS_SetElement(cx, rarray, len++, &val))
+					break;
+			}
 		}
-	}
 
-    *rval = OBJECT_TO_JSVAL(rarray);
+		*rval = OBJECT_TO_JSVAL(rarray);
+	}
 
     return(JS_TRUE);
 }
@@ -3257,7 +3257,7 @@ static jsSyncMethodSpec js_global_functions[] = {
 	{"socket_select",	js_socket_select,	0,	JSTYPE_ARRAY,	JSDOCSTR("[array of socket objects or descriptors] [,timeout=<tt>0</tt>] [,write=<tt>false</tt>]")
 	,JSDOCSTR("checks an array of socket objects or descriptors for read or write ability (default is <i>read</i>), "
 		"default timeout value is 0.0 seconds (immediate timeout), "
-		"returns an array of 0-based index values into the socket array, representing the sockets that were ready for reading or writing")
+		"returns an array of 0-based index values into the socket array, representing the sockets that were ready for reading or writing, or <i>null</i> on error")
 	,311
 	},
 	{"mkdir",			js_mkdir,			1,	JSTYPE_BOOLEAN,	JSDOCSTR("path/directory")
-- 
GitLab