[PATCH] new function stream_socket_create_pair

php.internals

six

21 years ago
hi, this patch against php-5.0.2 adds a stream_socket_create_pair() function. it's nearly identical to socket_create_pair() except it returns streams instead of socket resources. i'm currently rewriting a sockets daemon framework using streams with the added benefit of ssl and other stream goodies, but when it comes to IPC i have to use both stream_select() and socket_select(), which is quite disturbing and also requires the sockets extensions for something that's not really sockets anyway ... the patch is here : http://si.kz/~six/stream_socket_create_pair_patch.tgz i think this one, or at least some way in userspace to cast a socket resource to a stream one would be great. regards, Vincent

Wez Furlong

21 years ago
The essence of the patch is ok, it's just the checking of the type and domain args that is too magical. Probably the best thing to do is register integer constants for AF_INET etc., but name them STREAM_AF_INET, STREAM_AF_INET6, STREAM_AF_UNIX, STREAM_SOCK_STREAM and STREAM_SOCK_DGRAM. Look for REGISTER_LONG_CONSTANT in file.c to find where and how to register those constants. I'd also prefer to name the function stream_socket_pair(). If you can make those changes and then post a link to a unified diff against CVS (see README.SUBMITTING_PATCH in the PHP source for more hints), it can go in to PHP. Thanks :) --Wez. On Wed, 13 Oct 2004 02:36:03 +0200, six <six@t0x.net> wrote:

Sara Golemon

21 years ago
> the patch is here : http://si.kz/~six/stream_socket_create_pair_patch.tgz >
To add to Wez's comments, I'd rather see it return an array of socket streams (or FALSE on failure), rather than return true and tuck the streams into a by-ref parameter. -Sara

six

21 years ago
> > the patch is here :
http://si.kz/~six/stream_socket_create_pair_patch.tgz
> > > To add to Wez's comments, I'd rather see it return an array of socket > streams (or FALSE on failure), rather than return true and tuck the
streams
> into a by-ref parameter.
It would look simpler, but on the other hand it would break consistency with the behavior of socket_create_pair() and the sockpair() syscall ... If the above is not a problem for anyone i can rewrite it to return a streams array (or FALSE), without the byref param. regards, Vincent

six

21 years ago
Here is an updated version of the patch : http://si.kz/~six/stream_socket_pair.diff It now registers STREAM_AF_* and STREAM_SOCK_* long constants, checks the domain and type against known types and passes the array of created streams as return value instead of a byref param... and the diff is against today's CVS this time :) regards, Vincent ----- Original Message ----- From: "Vincent Negrier" <six@t0x.net> Newsgroups: php.internals To: <internals@lists.php.net> Sent: Wednesday, October 13, 2004 11:52 AM Subject: Re: [PATCH] new function stream_socket_create_pair
> > > the patch is here : > http://si.kz/~six/stream_socket_create_pair_patch.tgz > > > > > To add to Wez's comments, I'd rather see it return an array of socket > > streams (or FALSE on failure), rather than return true and tuck the > streams > > into a by-ref parameter. > > It would look simpler, but on the other hand it would break consistency
with

Andrey Hristov

21 years ago
Hi, at least my experience is that when a parameter's value is bad, FALSE is returned. In this case the code throws E_WARNING but continues exectuion assuming something. IMO it is better not to assume but to return FALSE. Thanks, Andrey Vincent NEGRIER wrote:

Vincent NEGRIER

21 years ago
I made the changes so that FALSE is returned : http://si.kz/~six/stream_socket_pair.noassume.diff regards, Vincent ----- Original Message ----- From: "Andrey Hristov" <php@hristov.com> Newsgroups: php.internals To: "Vincent NEGRIER" <six@t0x.net> Cc: "Wez Furlong" <kingwez@gmail.com>; <internals@lists.php.net> Sent: Wednesday, October 13, 2004 4:05 PM Subject: Re: [PHP-DEV] Re: [PATCH] new function stream_socket_create_pair
> Hi, > at least my experience is that when a parameter's value is bad, FALSE > is returned. In this case the code throws E_WARNING but continues
exectuion
> assuming something. IMO it is better not to assume but to return FALSE. > > Thanks, > Andrey > > Vincent NEGRIER wrote: > > Here is an updated version of the patch : > > http://si.kz/~six/stream_socket_pair.diff > > > > It now registers STREAM_AF_* and STREAM_SOCK_* long constants, checks
the
> > domain and type against known types and passes the array of created
streams
> > as return value instead of a byref param... and the diff is against
today's

Wez Furlong

21 years ago
I wouldn't bother checking against known types; let sockpair() handle that. It is possible that someone might want/need to use some other value which we haven't thought of, or are even aware of. --Wez. On Wed, 13 Oct 2004 15:58:46 +0200, Vincent NEGRIER <six@t0x.net> wrote:

six

21 years ago
hi, socket type checking removed : http://si.kz/~six/stream_socket_pair.notypecheck.diff Vincent Wez Furlong wrote: