#24629 [Asn->Csd]: socket_select() fails: "Reason: Invalid argument"

From: Date: Tue, 22 Jul 2003 07:21:39 +0000
Subject: #24629 [Asn->Csd]: socket_select() fails: "Reason: Invalid argument"
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-44477@lists.php.net to get a copy of this message
ID: 24629 Updated by: jason@php.net Reported By: zparta at skebo dot ac -Status: Assigned +Status: Closed Bug Type: Sockets related Operating System: FreeBSD 4.8 (Only!) PHP Version: 4.3.3RC2-dev Assigned To: jason New Comment: This bug has been fixed in CVS. In case this was a PHP problem, snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. In case this was a documentation problem, the fix will show up soon at http://www.php.net/manual/. In case this was a PHP.net website problem, the change will show up on the PHP.net site and on the mirror sites in short time. Thank you for the report, and for helping us make PHP better. Verified, apparently there are severl OSs that have this problem Previous Comments: ------------------------------------------------------------------------ [2003-07-21 10:13:09] jason@php.net I will take a look at this patch tonight -Jason ------------------------------------------------------------------------ [2003-07-20 16:26:01] meebey@php.net here the same patch for the stream_select() --- file.c.orig Sun Jul 20 23:25:34 2003 +++ file.c Sun Jul 20 23:24:55 2003 @@ -803,8 +803,15 @@ /* If seconds is not set to null, build the timeval, else we wait indefinitely */ if (sec != NULL) { convert_to_long_ex(&sec); - tv.tv_sec = Z_LVAL_P(sec); - tv.tv_usec = usec; + + if (usec > 999999) { + tv.tv_sec = Z_LVAL_P(sec)+(usec/1000000); + tv.tv_usec = usec%1000000; + } else { + tv.tv_sec = Z_LVAL_P(sec); + tv.tv_usec = usec; + } + tv_p = &tv; } ------------------------------------------------------------------------ [2003-07-20 16:13:56] meebey@php.net I found the problem with the select() under freebsd, the select() checks the timeout values (sec and usec). When they exceed the max value which is on freebsd for usec 999,999, after this number it must be 1 sec and not 1,000,000 usecs. This is whats happening here, the script wants 300,000,000 usecs, which are 300 seconds. Linux doesn't care about this and accepts this number (and works fine with it). I wrote the patch and tested it on the freebsd 4.8 box, strace now shows (as expected): select(4, [3], [], [], {300, 0} Here the patch which fixes this bug: --- sockets.c.orig Tue Jul 15 08:08:02 2003 +++ sockets.c Sun Jul 20 23:01:21 2003 @@ -591,8 +591,15 @@ convert_to_long(&tmp); sec = &tmp; } - tv.tv_sec = Z_LVAL_P(sec); - tv.tv_usec = usec; + + if (usec > 999999) { + tv.tv_sec = Z_LVAL_P(sec)+(usec/1000000); + tv.tv_usec = usec%1000000; + } else { + tv.tv_sec = Z_LVAL_P(sec); + tv.tv_usec = usec; + } + tv_p = &tv; if (sec == &tmp) { ------------------------------------------------------------------------ [2003-07-20 13:47:58] meebey@php.net I just straced the script with stream_select() and it's also getting the "Invalid argument" error msg. select(4, [3], [], [], {0, 300000000}) = -1 EINVAL (Invalid argument) ------------------------------------------------------------------------ [2003-07-20 13:18:46] meebey@php.net I tried using fsockopen and stream_select() on the freebsd box, and it returned false, so also some error happened. Is there a way of giving out the error msg of the failed stream_select()? ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/24629 -- Edit this bug report at http://bugs.php.net/?id=24629&edit=1

« previous php.bugs (#44477) next »