|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-07-12 20:23 UTC] zparta at skebo dot ac
Description: ------------ cant use socket_select in freebsd with neither 4.3.3rc1 or 4.3.2 when using real sockets not fsockets Reproduce code: --------------- dont have any Expected result: ---------------- dont know PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 20:00:01 2025 UTC |
Reproduce code: --------------- $this->_address = 'irc.homelien.no'; $this->_port = '6667'; $this->_socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); $result = @socket_connect($this->_socket, $this->_address, $this->_port); while ($this->_state() == SMARTIRC_STATE_CONNECTED) { $this->_checkbuffer(); $timeout = $this->_selecttimeout(); if ($this->_usesockets == true) { $sread = array($this->_socket); $result = @socket_select($sread, $w = null, $e = null, 0, $timeout*1000); if ($result == 1) { // the socket got data to read $rawdata = @socket_read($this->_socket, 10240); } else if ($result === false) { // panic! panic! something went wrong! $this->log(SMARTIRC_DEBUG_NOTICE, 'WARNING: socket_select() returned false, something went wrong! Reason: '.socket_strerror(socket_last_error()), __FILE__, __LINE__); exit; } else { // no data $rawdata = null; } //this code is taken from the Net_SmartIRC class from pear Expected result: ---------------- Jul 13 03:47:04 SmartIRC.php(1636) WARNING: socket_select() returned false, something went wrong! Reason: Invalid argument and the author of Net_SmartIRC has tested this on my machine and he says that i should bugreport this here because socket_select doesnt work on freebsd 4.8 dont know if it is version specific.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)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) {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; }