php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #13566 BUG FIX? for ext/sockets
Submitted: 2001-10-05 14:38 UTC Modified: 2001-11-21 10:40 UTC
From: jsmith at tutorbuddy dot com Assigned:
Status: Closed Package: Sockets related
PHP Version: 4.0CVS-2001-10-05 OS: linux kernel 2.4.2
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jsmith at tutorbuddy dot com
New email:
PHP Version: OS:

 

 [2001-10-05 14:38 UTC] jsmith at tutorbuddy dot com
I've been working with the sockets extension for PHP 
4.0.8-dev now for the past few days and I've noticed what 
must be a bug in socket_select(). 

Basically, socket_select() takes two parameters for 
timeout values in place of the single timeval struct that 
the standard select() function takes. With the standard 
select(), using a NULL instead of a timeout struct causes 
select() to block indefinitely. The socket_select() 
function in PHP doesn't have this capability, as calling 
socket_select() with NULL in both sec and usec end up in 
the timeval struct both as 0, setting the blocking timeout 
on the system select() call in turn to 0.

A quick fix: if sec and usec are both less than 0, pass 
NULL to the system select() call instead of a timeval 
struct with 0s for tv_sec and tv_usec. This will cause the 
desired effect of having socket_select() block 
indefinitely, as in system select() function.

Unfortunately, at the same time, this creates an 
incompatibility between socket_select() and system 
select(), since socket_select() will no longer produce the 
same results as calling select() with tv_sec = -1 and 
tv_usec = -1, but I don't think that's much of a problem.

I won't bother posting a patch because this will take all 
of 3 seconds to do. Here's my suggestion:

RETURN_LONG(select(max_fd+1, rfds ? &(rfds->set) : NULL,
                wfds ? &(wfds->set) : NULL,
                xfds ? &(xfds->set) : NULL,
                ((Z_LVAL_PP(arg4) < 0 && Z_LVAL_PP(arg5) < 
0) ? NULL : &tv)));


I was raking my brain trying to figure out why I couldn't 
do jack with socket_select(), and this seems to fix it.

Comments? Is it do-able?

J

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-11-21 07:15 UTC] mfischer@php.net
I don't promise to fix this myself but assigned it so I don't forget about this ...

Assigned to me.
 [2001-11-21 10:38 UTC] jsmith at tutorbuddy dot com
It seems that in the latest 4.1.0RC (and I assume in the 
4.2.0dev) this has been fixed. Omitting the last argument 
and passing NULL for tv_sec provides the expected 
behaviour, i.e. an indefinite blocking call...

J

 [2001-11-21 10:40 UTC] mfischer@php.net
Ok, well done :-)

Closing it.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC