#24629 [Opn]: socket_select() fails: "Reason: Invalid argument"

From: Date: Sun, 20 Jul 2003 21:26:02 +0000
Subject: #24629 [Opn]: socket_select() fails: "Reason: Invalid argument"
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-44387@lists.php.net to get a copy of this message
ID: 24629 Updated by: meebey@php.net Reported By: zparta at skebo dot ac Status: Open Bug Type: Sockets related Operating System: FreeBSD 4.8 (Only!) PHP Version: 4.3.3RC2-dev New Comment: 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; } Previous Comments: ------------------------------------------------------------------------ [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()? ------------------------------------------------------------------------ [2003-07-13 00:16:43] zparta at skebo dot ac ok thats to bad :( il just have to wait until its fixed ------------------------------------------------------------------------ [2003-07-13 00:04:21] sniper@php.net Works fine with latest CVS of PHP and SmartIRC. (under Linux, so it's propably yet another FreeBSD-only bug) ------------------------------------------------------------------------ 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 (#44387) next »