Edit report at https://bugs.php.net/bug.php?id=64654&edit=1

 ID:                 64654
 Comment by:         xilon dot jul at gmail dot com
 Reported by:        xilon dot jul at gmail dot com
 Summary:            socket_select returns false and socket_last_error
                     returns 0 (success)
 Status:             Open
 Type:               Bug
 Package:            Sockets related
 Operating System:   Linux 3.5.0-23-generic
 PHP Version:        5.4.14
 Block user comment: N
 Private report:     N

 New Comment:

Thanx laruence for your answer. I also "straced" the sample to check if the 
real 
sys call was invoked and indeed it is not. Php does some processing before 
giving the hand to the select sys call (checking valid fd, raising a warning as 
you mentionned).

However to give more control on Php side, I think a return code different from 
0 
must be returned. Even if it's not a "bug", my opinion is that there is a  
misconception here about raising a warning and having a success return code and 
that thinking that all that should be fined enough for PHP developpers.


Previous Comments:
------------------------------------------------------------------------
[2013-04-17 13:59:47] larue...@php.net

I don't think this is a bug.

the warning is threw before do really "select", it is an error in php side. not 
system call side.

and socket_last_error is for the error in system call side.

------------------------------------------------------------------------
[2013-04-17 09:52:28] xilon dot jul at gmail dot com

Description:
------------
When a socket ressource previously watched for read I/O in socket_select is 
closed, the socket_select function would return false and throw a warning 
saying 
"Not a valid socket ressource".

The fact is that subsequent call to socket_last_error() returns 0 which 
translates 
to success using socket_strerror().


Test script:
---------------
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
if (false === socket_bind($socket, '0.0.0.0', 5555)) {
        die('bind()');
}
$read[] = $socket;
// voluntarily close the socket
socket_close($socket);
// Will throw a warning and return false
$retval = socket_select($read, $w = null, $e = null, 1);
echo socket_last_error(); // returns 0


Expected result:
----------------
As the C select system call, closing the socket should return a valid system 
error 
code.

The C counterpart of this PHP sample above gives :

select(): Bad file descriptor (9 => EBADF)



Actual result:
--------------
The result of socket_last_error is 0.


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=64654&edit=1

Reply via email to