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:

hey laruence, first of all thanx four your involvement.
I've applied your patch against PHP 5.4.14 and executed the test script again, 
it works as it should.

socket_last_error now returns 9 which is what is expected.

A big thanx for your work.
What are the future actions now ? Should this bug fix be planned in a future 
php 
version ?


Previous Comments:
------------------------------------------------------------------------
[2013-04-18 05:40:15] larue...@php.net

hmm, I agree with you about give more info to php side.

but what do we define this error ? E_BADF?

simple fix is:

$ git diff
diff --git a/ext/sockets/sockets.c b/ext/sockets/sockets.c
index f305fa0..5f5b8c2 100644
--- a/ext/sockets/sockets.c
+++ b/ext/sockets/sockets.c
@@ -783,7 +783,14 @@ static int php_sock_array_to_fd_set(zval *sock_array, 
fd_set 
*fds, PHP_SOCKET *m
                num++;
        }

-       return num ? 1 : 0;
+       if (num) {
+               return 1;
+       } else {
+#ifdef EBADF
+               SOCKETS_G(last_error) = EBADF;
+#endif
+               return 0;
+       }
 }
 /* }}} */

------------------------------------------------------------------------
[2013-04-17 16:00:50] xilon dot jul at gmail dot com

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.

------------------------------------------------------------------------
[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