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

 ID:                 64654
 Updated by:         cataphr...@php.net
 Reported by:        xilon dot jul at gmail dot com
 Summary:            socket_select returns false and socket_last_error
                     returns 0 (success)
-Status:             Assigned
+Status:             Not a bug
 Type:               Bug
 Package:            Sockets related
 Operating System:   Linux 3.5.0-23-generic
 PHP Version:        5.4.14
 Assigned To:        cataphract
 Block user comment: N
 Private report:     N

 New Comment:

I would not change anything here. The problem is that the
socket resource at that point is not valid anymore. Its
value:

        resource(5) of type (Unknown)

If we are changing this, then all the socket functions
should set an EBAF when something other than a socket file
descriptor is passed. But we don't do that because argument
errors, usually detected at the zend_parse_parameters stage,
usually fail early, emit a message and function returns null
or false.

In this case, because we expect arrays of socket resources
and not just a socket resource, the check cannot be done
inside zend_parse_parameters. But I don't see why the
behavior should be different.

Marking as not a bug.


Previous Comments:
------------------------------------------------------------------------
[2013-04-18 13:43:45] larue...@php.net

@cataphract, do you think this fix makes sense?

if no objection, I will commit it into 5.4+

thanks

------------------------------------------------------------------------
[2013-04-18 09:23:11] xilon dot jul at gmail dot com

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 ?

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

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


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

    https://bugs.php.net/bug.php?id=64654


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

Reply via email to