# [PATCH] new function stream_socket_create_pair

- Thread: https://externals.io/message/13304
- Original archive: https://news-web.php.net/php.internals/13304
- Started by six@t0x.net on 2004-10-13T00:36:03+00:00
- Messages: 9
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #13304 — six@t0x.net — 2004-10-13T00:36:03+00:00

URL: https://externals.io/message/13304#13304

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

---

## #13306 — Wez Furlong — 2004-10-13T00:49:17+00:00

URL: https://externals.io/message/13304#13306 · In reply to: #13304

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.



> 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

---

## #13309 — Sara Golemon — 2004-10-13T01:43:18+00:00

URL: https://externals.io/message/13304#13309 · In reply to: #13304

> 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

---

## #13318 — Vincent NEGRIER — 2004-10-13T09:52:42+00:00

URL: https://externals.io/message/13304#13318 · In reply to: #13309

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

---

## #13320 — Vincent NEGRIER — 2004-10-13T13:58:46+00:00

URL: https://externals.io/message/13304#13320 · In reply to: #13318

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


> > […]
> http://si.kz/~six/stream_socket_create_pair_patch.tgz
> > […]
> streams
> > […]
>
> 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

---

## #13321 — Andrey Hristov — 2004-10-13T14:05:01+00:00

URL: https://externals.io/message/13304#13321 · In reply to: #13320

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
> 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
> 
> 
> 
> > […]
> 
> with
> 
> > […]

---

## #13322 — Vincent NEGRIER — 2004-10-13T14:18:41+00:00

URL: https://externals.io/message/13304#13322 · In reply to: #13321

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:
> > […]
the
> > […]
streams
> > […]
today's
> > […]

---

## #13326 — Wez Furlong — 2004-10-13T15:47:40+00:00

URL: https://externals.io/message/13304#13326 · In reply to: #13320

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.


> 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 :)

---

## #13329 — six@t0x.net — 2004-10-13T18:28:45+00:00

URL: https://externals.io/message/13304#13329 · In reply to: #13326

hi,

socket type checking removed : 
http://si.kz/~six/stream_socket_pair.notypecheck.diff

Vincent

Wez Furlong wrote:

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