Hello friends,
I have a couple of questions about sockets and file descriptors.
 
In my extension I make use of a ordinary c socket and two fds build on it. 
I want this connection to be kept over request, therefore I put a struct 
pointer containing this into the persistant_list of the zend engine. 

I made it like the mysql extension, which is looking for an already opened 
connection by zend_hash_find(). If a connection already exists, it will be 
used, if not, a new connection struct is malloced (not emalloc()) and 
inserted into a new list_entry, which is immediately hashed into the 
persistand list. As key I use a emalloced string, consisting of a prefix 
and the session id, since I need to map sessions to connections.
 
I've also implement a zend_list_destructor for a persistent resource, 
actual the allocated conn. struct. There the items of the struct will be 
freed by fclose(), close() and at last the whole struct by free().

The exported extension functions are calling sometimes not exported  
functions, which are not introduced by the function list macro. This 
functions do some not-zend-related-stuff, but make use of the allocated 
connection. 

The initialization of the connection succeed, the functions in the same 
request are working how I want them to, but the explicitly closing of the 
connection causes a segfault. If a new request attempts to reuse the 
connection, the fds are lost, respectively the connection struct pointer 
seems to be invalid -> segfault.

Now my questions: 
1. Is there anything to know about using standart c sockets and fds within 
php extensions?
2. Do pointers stay valid over request end, if they're malloced (not 
emalloc())?
3. Should anything be considered about additional c functions, which not 
exported? (if at all...)

I am not experienced with threads, therefore I might have forget some 
details...about allocations in threads an so on...

Good night and best regards
Ron


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to