#34851 [Fbk->Opn]: SO_RECVTIMEO sec stands for usec!!!! and usec has no effect!

From: Date: Thu, 13 Oct 2005 12:36:04 +0000
Subject: #34851 [Fbk->Opn]: SO_RECVTIMEO sec stands for usec!!!! and usec has no effect!
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-86527@lists.php.net to get a copy of this message
ID: 34851 User updated by: khayll at motoros dot hu Reported By: khayll at motoros dot hu -Status: Feedback +Status: Open Bug Type: Sockets related Operating System: win 2k3 server PHP Version: 4.4.0 New Comment: <?php $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec"=>5, "usec"=>0)); socket_connect($socket, "81.182.13.109", "502"); $pdu = ""; $pdu .= chr(0x03).chr(floor(16000 / 256)).chr(16000 % 256).chr(floor(10 / 256)).chr(10 % 256); $rand = mt_rand(1,65535); //generate random adu id $adu = ""; $adu .= chr(floor($rand / 256)).chr($rand % 256).chr(0).chr(0).chr(floor(6 / 256)).chr(6 % 256).chr(1); socket_write($socket, $data, strlen($data)); $result = socket_read($socket, 512, PHP_BINARY_READ); echo socket_strerror(socket_last_error()); socket_shutdown($socket, 2); socket_close($socket); ?> Previous Comments: ------------------------------------------------------------------------ [2005-10-13 12:31:30] tony2001@php.net Thank you for this bug report. To properly diagnose the problem, we need a short but complete example script to be able to reproduce this bug ourselves. A proper reproducing script starts with <?php and ends with ?>, is max. 10-20 lines long and does not require any external resources such as databases, etc. If possible, make the script source available online and provide an URL to it here. Try to avoid embedding huge scripts into the report. ------------------------------------------------------------------------ [2005-10-13 11:38:15] khayll at motoros dot hu Description: ------------ I tried to set a receive timeout for a socket, but found out that sec is used as usec, and usec is in fact ignored! Reproduce code: --------------- using a modbus device with "address" address, sorry i cannot make it available on the net $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec"=>0, "usec"=>500)); socket_connect($socket, "address", "502"); socket_write($this->socket, $data, strlen($data)); socket_read($this->socket, 512, PHP_BINARY_READ); Expected result: ---------------- expected to read some data or give a timeout error. Actual result: -------------- code hangs, so i figured out, that usec has no effect, then i tried 1 sec as timeout, code began to work, but kept reporting timeout, so i figured out if i try a value like 500000 as sec it works. Seems like sec is used as usec, and usec has no effect. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=34851&edit=1

« previous php.bugs (#86527) next »