|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-04-17 09:52 UTC] 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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 20:00:02 2025 UTC |
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; + } } /* }}} */