# Zend resources

- Thread: https://externals.io/message/18779
- Original archive: https://news-web.php.net/php.internals/18779
- Started by ScriptBlue@nyc.rr.com on 2005-09-11T19:18:43+00:00
- Messages: 11
- 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

---

## #18779 — ScriptBlue@nyc.rr.com — 2005-09-11T19:18:43+00:00

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

I've created a new module, which is an improvement to the socket library. I
however do not plan on re-writing every single function. So I need to find a
way to somehow access the socket library's resources. My question is, is
there a way to access another module's resource?

---

## #18780 — Wez Furlong — 2005-09-11T20:50:44+00:00

URL: https://externals.io/message/18779#18780 · In reply to: #18779

The module whose resources you are accessing needs to export a
function that will give you the list id, and also publish their
structure layout in a header file.

Just out of interest, what functions are in your extension?

--Wez.



> I've created a new module, which is an improvement to the socket library. I
> however do not plan on re-writing every single function. So I need to find a
> way to somehow access the socket library's resources. My question is, is
> there a way to access another module's resource?

---

## #18781 — ScriptBlue@nyc.rr.com — 2005-09-11T22:54:49+00:00

URL: https://externals.io/message/18779#18781 · In reply to: #18780

"Wez Furlong" <kingwez@gmail.com> wrote in message
news:4e89b426050911135030c1aebe@mail.gmail.com...
The module whose resources you are accessing needs to export a
function that will give you the list id, and also publish their
structure layout in a header file.

Just out of interest, what functions are in your extension?

--Wez.



> I've created a new module, which is an improvement to the socket library.
I
> however do not plan on re-writing every single function. So I need to find
a
> way to somehow access the socket library's resources. My question is, is
> there a way to access another module's resource?

---

## #18857 — ScriptBlue@nyc.rr.com — 2005-09-11T22:56:28+00:00

URL: https://externals.io/message/18779#18857 · In reply to: #18780

"Wez Furlong" <kingwez@gmail.com> wrote in message
news:4e89b426050911135030c1aebe@mail.gmail.com...
The module whose resources you are accessing needs to export a
function that will give you the list id, and also publish their
structure layout in a header file.

Just out of interest, what functions are in your extension?

--Wez.



> I've created a new module, which is an improvement to the socket library.
I
> however do not plan on re-writing every single function. So I need to find
a
> way to somehow access the socket library's resources. My question is, is
> there a way to access another module's resource?

---

## #18783 — Wez Furlong — 2005-09-11T23:26:31+00:00

URL: https://externals.io/message/18779#18783

> Well, I've improved the socket_accept and socket_connect functions and I've
> name them socketi_*. socketi_accept returns the IP as well as the port
> number, and socket_connect has a timeout function.

Have you seen `stream_socket_server()`, `stream_socket_accept()`,
 `stream_socket_get_name()` and `stream_socket_client()` in PHP 5?

> By the way, what function should give me the list id?
> zend_list_find() or something similar?

The sockets extension would need to provide a new function that
returns the value of le_socket, which you'd then use in the same way
that the sockets extension does.

--Wez.

---

## #18784 — ScriptBlue@nyc.rr.com — 2005-09-11T23:48:39+00:00

URL: https://externals.io/message/18779#18784 · In reply to: #18783

Yeah I have seen those functions, but they are quite bloated in my opnion.
Is there any way of getting the resource id without modifying sockets?
"Wez Furlong" <kingwez@gmail.com> wrote in message
news:4e89b4260509111626ccfcf2b@mail.gmail.com...

> Well, I've improved the socket_accept and socket_connect functions and
I've
> name them socketi_*. socketi_accept returns the IP as well as the port
> number, and socket_connect has a timeout function.

Have you seen `stream_socket_server()`, `stream_socket_accept()`,
 `stream_socket_get_name()` and `stream_socket_client()` in PHP 5?

> By the way, what function should give me the list id?
> zend_list_find() or something similar?

The sockets extension would need to provide a new function that
returns the value of le_socket, which you'd then use in the same way
that the sockets extension does.

--Wez.

---

## #18786 — Wez Furlong — 2005-09-12T01:19:07+00:00

URL: https://externals.io/message/18779#18786 · In reply to: #18784

> Yeah I have seen those functions, but they are quite bloated in my opnion.

Maybe so, but at least they work :)

> Is there any way of getting the resource id without modifying sockets?

Nope.

--Wez.

> "Wez Furlong" <kingwez@gmail.com> wrote in message
> news:4e89b4260509111626ccfcf2b@mail.gmail.com...
> 
> > […]
> I've
> > […]
> 
> Have you seen `stream_socket_server()`, `stream_socket_accept()`,
> `stream_socket_get_name()` and `stream_socket_client()` in PHP 5?
> 
> > […]
> 
> The sockets extension would need to provide a new function that
> returns the value of le_socket, which you'd then use in the same way
> that the sockets extension does.
> 
> --Wez.

---

## #18788 — Sara Golemon — 2005-09-12T04:01:50+00:00

URL: https://externals.io/message/18779#18788 · In reply to: #18784

> Is there any way of getting the resource id without modifying sockets?
>
ZEND_API int zend_fetch_list_dtor_id(char *type_name);


As an implementation:

In *your* socketi.c:

static int le_socket = -1;

PHP_RINIT(socketi)
{
    if (le_socket == -1) {
        le_socket = zend_fetch_list_dtor_id("Socket");
    }

    return (le_socket == -1) ? FAILURE : SUCCESS;
}



By doing it in RINIT you avoid the potential problem of having socketi 
loaded before socket (which could happen if they're both shared).  Once the 
first request has retreived it, later requests won't have to try because 
it'll be persistently known from then on.

The one pitfall to this method is that *IF* another ext defines a resource 
named "Socket" (case-sensitive), you could pick up the wrong lde ID.  Fairly 
left-field chance, but technically not impossible.

-Sara

---

## #18789 — Sara Golemon — 2005-09-12T04:06:02+00:00

URL: https://externals.io/message/18779#18789 · In reply to: #18788

> static int le_socket = -1;
> 
Scratch that, those instances of -1 should have been 0....
(Which is what zend_fetch_list_dtor_id() returns as failure)

---

## #18851 — ScriptBlue@nyc.rr.com — 2005-09-13T23:48:27+00:00

URL: https://externals.io/message/18779#18851 · In reply to: #18789

wow thanks, I'm gonna go and try it out right now and tell you my results
""Sara Golemon"" <saramg@berkeley.edu> wrote in message
news:004501c5b74f$4a5ee6c0$6c051fac@lighthammer...
> > […]
> Scratch that, those instances of -1 should have been 0....
> (Which is what zend_fetch_list_dtor_id() returns as failure)

---

## #18856 — ScriptBlue@nyc.rr.com — 2005-09-14T00:52:15+00:00

URL: https://externals.io/message/18779#18856 · In reply to: #18789

Yep, that did work, thanks a lot
