Re: [PHP-DEV] cvs socket extension
At 20:15 24.07.2001 +0200, Markus Fischer wrote: I've come up with a patch based on the ideas and suggestion that came up in this thread: - Let the fd_set resource keep track of the highest socket; nuked _select() first parameter and determine it ourself - Swapped _set(), _clear() and _isset() parameters and recognize plain sockets as well as array of sockets The patch is against current CVS and only compiled unter linux (debian unstable) so far. Please everyone interested test and verify it and let me know what you think. Due my lack of karma I can't commit it anyway, feel free to do so if you find it appropriate. please let me know wether the attached patch fixes your concerns. daniel /*-- daniel beulshausen - [EMAIL PROTECTED] using php on windows? http://www.php4win.de Index: php_sockets.h === RCS file: /repository/php4/ext/sockets/php_sockets.h,v retrieving revision 1.10 diff -u -r1.10 php_sockets.h --- php_sockets.h 21 May 2001 19:36:22 - 1.10 +++ php_sockets.h 25 Jul 2001 17:19:04 - @@ -78,21 +78,30 @@ PHP_FUNCTION(socket_shutdown); typedef struct php_iovec { - struct iovec *iov_array; - unsigned int count; + struct iovec*iov_array; + unsigned intcount; } php_iovec_t; -typedef struct { -#ifdef PHP_WIN32 - SOCKET socket; -#else - int socket; +#ifndef PHP_WIN32 +typedef int SOCKET; #endif - int type; + +typedef struct { + SOCKET socket; + int type; } php_socket; typedef struct { - zend_bool use_system_read; + fd_set set; + SOCKET max_fd; +} php_fd_set; + +typedef struct { + unsigned char info[256]; +} php_sockaddr_storage; + +typedef struct { + zend_bool use_system_read; } php_sockets_globals; Index: php_sockets_win.h === RCS file: /repository/php4/ext/sockets/php_sockets_win.h,v retrieving revision 1.1 diff -u -r1.1 php_sockets_win.h --- php_sockets_win.h 17 May 2001 17:02:37 - 1.1 +++ php_sockets_win.h 25 Jul 2001 17:19:05 - @@ -41,7 +41,6 @@ #define set_h_errno(a) WSASetLastError(a) #define close(a) closesocket(a) #define CMSG_DATA(cmsg) ((cmsg)-cmsg_data) -#define IS_INVALID_SOCKET(a) (a-socket == INVALID_SOCKET) typedef long ssize_t; Index: sockets.c === RCS file: /repository/php4/ext/sockets/sockets.c,v retrieving revision 1.56 diff -u -r1.56 sockets.c --- sockets.c 16 Jul 2001 04:31:13 - 1.56 +++ sockets.c 25 Jul 2001 17:19:06 - @@ -55,13 +55,14 @@ # include fcntl.h # include signal.h # include sys/uio.h -# define IS_INVALID_SOCKET(a) (a-socket 0) +# define IS_INVALID_SOCKET(a) (a-socket 0) # define set_errno(a) (errno = a) # define set_h_errno(a) (h_errno = a) #else /* windows */ # include winsock.h # include php_sockets.h # include php_sockets_win.h +# define IS_INVALID_SOCKET(a) (a-socket == INVALID_SOCKET) #endif #ifdef ZTS @@ -91,10 +92,6 @@ #define PHP_NORMAL_READ 0x0001 #define PHP_BINARY_READ 0x0002 -typedef struct { - unsigned char info[256]; -} php_sockaddr_storage; - static int le_iov; #define le_iov_name Socket I/O vector @@ -178,8 +175,8 @@ static void destroy_fd_sets(zend_rsrc_list_entry *rsrc) { - fd_set *set = (fd_set *) rsrc-ptr; - efree(set); + php_fd_set *php_fd = (php_fd_set*)rsrc-ptr; + efree(php_fd); } static void destroy_iovec(zend_rsrc_list_entry *rsrc) @@ -338,7 +335,7 @@ struct protoent *pe; le_socket = zend_register_list_destructors_ex(destroy_socket, NULL, le_socket_name, module_number); - le_destroy = zend_register_list_destructors_ex(destroy_fd_sets,NULL, le_destroy_name, module_number); + le_destroy = zend_register_list_destructors_ex(destroy_fd_sets, NULL, +le_destroy_name, module_number); le_iov = zend_register_list_destructors_ex(destroy_iovec, NULL, le_iov_name, module_number); REGISTER_LONG_CONSTANT(AF_UNIX, AF_UNIX, CONST_CS | CONST_PERSISTENT); @@ -397,13 +394,13 @@ Allocates a new file descriptor set */ PHP_FUNCTION(socket_fd_alloc) { - fd_set *set; + php_fd_set *php_fd; - set = emalloc(sizeof *set); - - FD_ZERO(set); + php_fd = (php_fd_set*)emalloc(sizeof(php_fd_set)); + + FD_ZERO((php_fd-set)); - ZEND_REGISTER_RESOURCE(return_value, set, le_destroy); + ZEND_REGISTER_RESOURCE(return_value, php_fd, le_destroy); } /* }}} */ @@ -412,75 +409,106 @@ PHP_FUNCTION(socket_fd_free) { zval **arg1; - fd_set *the_set; + php_fd_set *php_fd; if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, arg1) == FAILURE) { WRONG_PARAM_COUNT; } -
Re: [PHP-DEV] cvs socket extension
On Wed, Jul 25, 2001 at 07:20:57PM +0200, Daniel Beulshausen wrote : At 20:15 24.07.2001 +0200, Markus Fischer wrote: I've come up with a patch based on the ideas and suggestion that came up in this thread: - Let the fd_set resource keep track of the highest socket; nuked _select() first parameter and determine it ourself - Swapped _set(), _clear() and _isset() parameters and recognize plain sockets as well as array of sockets The patch is against current CVS and only compiled unter linux (debian unstable) so far. Please everyone interested test and verify it and let me know what you think. Due my lack of karma I can't commit it anyway, feel free to do so if you find it appropriate. please let me know wether the attached patch fixes your concerns. It works fine! I had another patch (which is obsolete now) which a) let the user pass 0 (or NULL) for all fd set resources to socket_select() (which is perfectly valid because that way you can wait a specified amount of time in seconds and finer) and which also allowed to zero an array of fd set resources. Do you think you can take on that changes ? - Markus -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] cvs socket extension
At 23:25 25.07.2001 +0200, Markus Fischer wrote: It works fine! I had another patch (which is obsolete now) which a) let the user pass 0 (or NULL) for all fd set resources to socket_select() (which is perfectly valid because that way you can wait a i don't think this is needed, it would behave like (u)sleep ( besides that it won't work under win32 :) ) specified amount of time in seconds and finer) and which also allowed to zero an array of fd set resources. not sure about this one, but if (we want to do this) we should determine for which fd functions it would make sense too (i.e. socket_fd_free) daniel /*-- daniel beulshausen - [EMAIL PROTECTED] using php on windows? http://www.php4win.de -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] cvs socket extension
On Thu, Jul 26, 2001 at 12:12:43AM +0200, Daniel Beulshausen wrote : At 23:25 25.07.2001 +0200, Markus Fischer wrote: It works fine! I had another patch (which is obsolete now) which a) let the user pass 0 (or NULL) for all fd set resources to socket_select() (which is perfectly valid because that way you can wait a i don't think this is needed, it would behave like (u)sleep ( besides that it won't work under win32 :) ) Hehe, oh well specified amount of time in seconds and finer) and which also allowed to zero an array of fd set resources. not sure about this one, but if (we want to do this) we should determine for which fd functions it would make sense too (i.e. socket_fd_free) I give a +1 for _zero() and _clear() for being the second parameter an array of resources instead of just one. - Markus (likes seeing this commited soon :) -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] cvs socket extension
At 20:15 24.07.2001 +0200, Markus Fischer wrote: I've come up with a patch based on the ideas and suggestion that came up in this thread: - Let the fd_set resource keep track of the highest socket; nuked _select() first parameter and determine it ourself - Swapped _set(), _clear() and _isset() parameters and recognize plain sockets as well as array of sockets The patch is against current CVS and only compiled unter linux (debian unstable) so far. Please everyone interested test and verify it and let me know what you think. Due my lack of karma I can't commit it anyway, feel free to do so if you find it appropriate. please let me know wether the attached patch fixes your concerns. Looks good. But it doesn't matter if someone passes no sets into select(): if there are no sets, it essentially becomes a usleep(). Chris -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] cvs socket extension
On Wed, Jul 25, 2001 at 06:37:25PM -0700, Chris Vandomelen wrote : At 20:15 24.07.2001 +0200, Markus Fischer wrote: I've come up with a patch based on the ideas and suggestion that came up in this thread: - Let the fd_set resource keep track of the highest socket; nuked _select() first parameter and determine it ourself - Swapped _set(), _clear() and _isset() parameters and recognize plain sockets as well as array of sockets The patch is against current CVS and only compiled unter linux (debian unstable) so far. Please everyone interested test and verify it and let me know what you think. Due my lack of karma I can't commit it anyway, feel free to do so if you find it appropriate. please let me know wether the attached patch fixes your concerns. Looks good. But it doesn't matter if someone passes no sets into select(): if there are no sets, it essentially becomes a usleep(). Yes I know, I had another patch which took care of this. But Daniels latest commit took care of everything, looks very good now :) - Markus -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] cvs socket extension
Looks good. But it doesn't matter if someone passes no sets into select(): if there are no sets, it essentially becomes a usleep(). Yes I know, I had another patch which took care of this. But Daniels latest commit took care of everything, looks very good now :) I saw the patch :) Just didn't get far enough through my inbox to notice that it had been committed .. especially since it was buried in about 200 other messages. :) Chris -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] cvs socket extension
On Tue, Jul 24, 2001 at 05:16:05AM +0200, Markus Fischer wrote: Great :-) So we're seeing this getting implemented soon ? Volunteers, anyone ? :-)) Is this select stuff so brand new that it's okay to change the API? If it is, we should do it quickly before too many people get to play with it. I think I agree now with just using the max, we can always optimize more later if we feel it's necessary, I think the most important thing now is to get rid of that argument if possible (: Stig -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] cvs socket extension
On Tue, Jul 24, 2001 at 05:16:05AM +0200, Markus Fischer wrote: Great :-) So we're seeing this getting implemented soon ? Volunteers, anyone ? :-)) Is this select stuff so brand new that it's okay to change the API? If it is, we should do it quickly before too many people get to play with it. I think I agree now with just using the max, we can always optimize more later if we feel it's necessary, I think the most important thing now is to get rid of that argument if possible (: The new version (renamed, cleaned up) is fairly new, so it should be fine to do that. Chris -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] cvs socket extension
On Tue, Jul 24, 2001 at 05:48:33AM -0700, Chris Vandomelen wrote : On Tue, Jul 24, 2001 at 05:16:05AM +0200, Markus Fischer wrote: Great :-) So we're seeing this getting implemented soon ? Volunteers, anyone ? :-)) Is this select stuff so brand new that it's okay to change the API? If it is, we should do it quickly before too many people get to play with it. I think I agree now with just using the max, we can always optimize more later if we feel it's necessary, I think the most important thing now is to get rid of that argument if possible (: The new version (renamed, cleaned up) is fairly new, so it should be fine to do that. While we're at it, wouldn't it be more intuitiv to modify the socket_fd_*() calls to accept the fd_set resource as first parameter and the fd to add or remove as second parameter ? For socket_fd_set() I'ld also vote to let the second parameter be a single socket or an array of sockets (when you're dealing with many connection you're likely holding them in an array than in separate vars); same for socket_fd_clear(). Maybe, but I haven't thought more about it, it would make sense for _isset() [after writing this sentence I think not :) ]. - Markus -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] cvs socket extension
The new version (renamed, cleaned up) is fairly new, so it should be fine to do that. While we're at it, wouldn't it be more intuitiv to modify the socket_fd_*() calls to accept the fd_set resource as first parameter and the fd to add or remove as second parameter ? No problem with that request. I'll still get them confused though. :) For socket_fd_set() I'ld also vote to let the second parameter be a single socket or an array of sockets (when you're dealing with many connection you're likely holding them in an array than in separate vars); same for socket_fd_clear(). Maybe, but I haven't thought more about it, it would make sense for _isset() [after writing this sentence I think not :) ]. *_set() and *_clear() it makes sense to accept an array for. *_isset(), OTOH, it doesn't. Oh, I want to know if any of the fds 5, 6, 7, or 8 are set... somehow that doesn't seem quite kosher. :) Chris -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] cvs socket extension
On Tue, Jul 24, 2001 at 08:34:44AM -0700, Chris Vandomelen wrote : The new version (renamed, cleaned up) is fairly new, so it should be fine to do that. While we're at it, wouldn't it be more intuitiv to modify the socket_fd_*() calls to accept the fd_set resource as first parameter and the fd to add or remove as second parameter ? No problem with that request. I'll still get them confused though. :) For socket_fd_set() I'ld also vote to let the second parameter be a single socket or an array of sockets (when you're dealing with many connection you're likely holding them in an array than in separate vars); same for socket_fd_clear(). Maybe, but I haven't thought more about it, it would make sense for _isset() [after writing this sentence I think not :) ]. *_set() and *_clear() it makes sense to accept an array for. *_isset(), OTOH, it doesn't. Oh, I want to know if any of the fds 5, 6, 7, or 8 are set... somehow that doesn't seem quite kosher. :) I've come up with a patch based on the ideas and suggestion that came up in this thread: - Let the fd_set resource keep track of the highest socket; nuked _select() first parameter and determine it ourself - Swapped _set(), _clear() and _isset() parameters and recognize plain sockets as well as array of sockets The patch is against current CVS and only compiled unter linux (debian unstable) so far. Please everyone interested test and verify it and let me know what you think. Due my lack of karma I can't commit it anyway, feel free to do so if you find it appropriate. - Markus -- Markus Fischer, http://guru.josefine.at/~mfischer/ EMail: [EMAIL PROTECTED] PGP Public Key: http://guru.josefine.at/~mfischer/C2272BD0.asc PGP Fingerprint: D3B0 DD4F E12B F911 3CE1 C2B5 D674 B445 C227 2BD0 ? .php_sockets.h.swp ? .sockets.c.swp Index: php_sockets.h === RCS file: /repository/php4/ext/sockets/php_sockets.h,v retrieving revision 1.10 diff -u -r1.10 php_sockets.h --- php_sockets.h 21 May 2001 19:36:22 - 1.10 +++ php_sockets.h 24 Jul 2001 17:59:52 - @@ -82,6 +82,11 @@ unsigned int count; } php_iovec_t; +typedef struct php_fd_set { + fd_set set; + int max_fd; +} php_fd_set_t; + typedef struct { #ifdef PHP_WIN32 SOCKET socket; Index: sockets.c === RCS file: /repository/php4/ext/sockets/sockets.c,v retrieving revision 1.56 diff -u -r1.56 sockets.c --- sockets.c 16 Jul 2001 04:31:13 - 1.56 +++ sockets.c 24 Jul 2001 18:00:01 - @@ -178,8 +178,8 @@ static void destroy_fd_sets(zend_rsrc_list_entry *rsrc) { - fd_set *set = (fd_set *) rsrc-ptr; - efree(set); + php_fd_set_t *the_set = (php_fd_set_t *) rsrc-ptr; + efree(the_set); } static void destroy_iovec(zend_rsrc_list_entry *rsrc) @@ -397,13 +397,14 @@ Allocates a new file descriptor set */ PHP_FUNCTION(socket_fd_alloc) { - fd_set *set; + php_fd_set_t *the_set; - set = emalloc(sizeof *set); + the_set = emalloc(sizeof(php_fd_set_t)); - FD_ZERO(set); + FD_ZERO((the_set-set)); + the_set-max_fd = -1; - ZEND_REGISTER_RESOURCE(return_value, set, le_destroy); + ZEND_REGISTER_RESOURCE(return_value, the_set, le_destroy); } /* }}} */ @@ -412,75 +413,97 @@ PHP_FUNCTION(socket_fd_free) { zval **arg1; - fd_set *the_set; + php_fd_set_t *the_set; if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, arg1) == FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(the_set, fd_set *, arg1, -1, le_destroy_name, le_destroy); + ZEND_FETCH_RESOURCE(the_set, php_fd_set_t *, arg1, -1, le_destroy_name, +le_destroy); zend_list_delete(Z_RESVAL_PP(arg1)); RETURN_TRUE; } /* }}} */ -/* {{{ proto bool socket_fd_set(resource socket, resource set) +/* {{{ proto bool socket_fd_set(resource set, mixed socket) Adds a file descriptor to a set */ PHP_FUNCTION(socket_fd_set) { - zval **arg1, **arg2; - fd_set *the_set; + zval **arg1, **arg_socket, **arg_socket_entry; + php_fd_set_t *the_set; php_socket *php_sock; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, arg1, arg2) == FAILURE) { + if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, arg1, arg_socket) == +FAILURE) { WRONG_PARAM_COUNT; } - ZEND_FETCH_RESOURCE(php_sock, php_socket*, arg1, -1, le_socket_name, le_socket); - ZEND_FETCH_RESOURCE(the_set, fd_set*, arg2, -1, le_destroy_name, le_destroy); + ZEND_FETCH_RESOURCE(the_set, php_fd_set_t*, arg1, -1, le_destroy_name, +le_destroy); + if( Z_TYPE_PP( arg_socket) == IS_ARRAY) { + zend_hash_internal_pointer_reset( Z_ARRVAL_PP( arg_socket)); +
[PHP-DEV] cvs socket extension
Morning ... Has anyone a working example on using the new socket_select() call with non-blocking connection-oriented sockets? blocking sockets with socket_accept() work like a charm. But I can't get socket_select() to work. ty - Markus -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] cvs socket extension
Morning ... Has anyone a working example on using the new socket_select() call with non-blocking connection-oriented sockets? blocking sockets with socket_accept() work like a charm. But I can't get socket_select() to work. That's because of the patches that were made. Try specifying 0x7FFF or something equally large for max_fd (the first argument to select) and it *should* work. The reason it doesn't work is because file descriptors were changed from ints to resources, and since the first argument to select() (and therefore socket_select()) must be greater than the largest file descriptor in the set, and resource number != file descriptor.. should be obvious. :) Try something like: -- $someport = 3334; $fd = socket_create_listen($someport, 5); $fd_set = socket_fd_alloc(); socket_fd_set($fd, $fd_set); socket_select(0x7fff, $fd_set, 0, 0, 0, 0); -- to force the select function to see all of the file descriptors in the set (as the socket_fd_* functions do the Right Thing when dealing with the resources). Chris ty - Markus -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] cvs socket extension
Thanks for the quick response! Exactly that was what I thought. I've used system select() before and I knew what I needed for the first parameter but heck I got no idea from which var/fucntion to retrieve this value. thanks ! - Markus On Mon, Jul 23, 2001 at 05:14:29AM -0700, Chris Vandomelen wrote : Morning ... Has anyone a working example on using the new socket_select() call with non-blocking connection-oriented sockets? blocking sockets with socket_accept() work like a charm. But I can't get socket_select() to work. That's because of the patches that were made. Try specifying 0x7FFF or something equally large for max_fd (the first argument to select) and it *should* work. The reason it doesn't work is because file descriptors were changed from ints to resources, and since the first argument to select() (and therefore socket_select()) must be greater than the largest file descriptor in the set, and resource number != file descriptor.. should be obvious. :) Try something like: -- $someport = 3334; $fd = socket_create_listen($someport, 5); $fd_set = socket_fd_alloc(); socket_fd_set($fd, $fd_set); socket_select(0x7fff, $fd_set, 0, 0, 0, 0); -- to force the select function to see all of the file descriptors in the set (as the socket_fd_* functions do the Right Thing when dealing with the resources). Chris ty - Markus -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- Markus Fischer, http://guru.josefine.at/~mfischer/ EMail: [EMAIL PROTECTED] PGP Public Key: http://guru.josefine.at/~mfischer/C2272BD0.asc PGP Fingerprint: D3B0 DD4F E12B F911 3CE1 C2B5 D674 B445 C227 2BD0 -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] cvs socket extension
At 05:14 23.07.2001 -0700, Chris Vandomelen wrote: Morning ... Has anyone a working example on using the new socket_select() call with non-blocking connection-oriented sockets? blocking sockets with socket_accept() work like a charm. But I can't get socket_select() to work. That's because of the patches that were made. Try specifying 0x7FFF or something equally large for max_fd (the first argument to select) and it *should* work. The reason it doesn't work is because file descriptors were changed from ints to resources, and since the first argument to select() (and therefore socket_select()) must be greater than the largest file descriptor in the set, and resource number != file descriptor.. should be obvious. :) Try something like: -- $someport = 3334; $fd = socket_create_listen($someport, 5); $fd_set = socket_fd_alloc(); socket_fd_set($fd, $fd_set); socket_select(0x7fff, $fd_set, 0, 0, 0, 0); we can add a support function which return's the php_socket-socket integer. daniel /*-- daniel beulshausen - [EMAIL PROTECTED] using php on windows? http://www.php4win.de -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] cvs socket extension
On Mon, Jul 23, 2001 at 07:20:34AM -0700, Chris Vandomelen wrote : socket_select(0x7fff, $fd_set, 0, 0, 0, 0); we can add a support function which return's the php_socket-socket integer. Glad someone came up with this. Since socket_select() always wants highest +1, couldn't this be implemented into socket_select() to go through all socket sets and get the number itself ? Or are there good reasons to let the user specify the value on its own ? In theory, the user isn't going to be specifying sockets that aren't accessible as resources. The best way around this (IMHO) is to define a php_fd_set something like: struct php_fd_set { fd_set the_set; intmax_fd; }; Then, whenver someone calls fd_set() or fd_zero(), change php_fd_set.max_fd appropriately as well as updating php_fd_set.the_set, and in socket_select(), check all of the max_fd values. Removing the first arg to socket_select(), if that's implemented, wouldn't be a bad idea either. +1 But, someone with good knowledge of socket should comment if it ever makes sense not to specify highest+1 so we can really drop the first parameter. - Markus -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] cvs socket extension
socket_select(0x7fff, $fd_set, 0, 0, 0, 0); we can add a support function which return's the php_socket-socket integer. Glad someone came up with this. Since socket_select() always wants highest +1, couldn't this be implemented into socket_select() to go through all socket sets and get the number itself ? Or are there good reasons to let the user specify the value on its own ? In theory, the user isn't going to be specifying sockets that aren't accessible as resources. The best way around this (IMHO) is to define a php_fd_set something like: struct php_fd_set { fd_set the_set; intmax_fd; }; Then, whenver someone calls fd_set() or fd_zero(), change php_fd_set.max_fd appropriately as well as updating php_fd_set.the_set, and in socket_select(), check all of the max_fd values. Removing the first arg to socket_select(), if that's implemented, wouldn't be a bad idea either. Chris -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] cvs socket extension
On Mon, Jul 23, 2001 at 07:20:34AM -0700, Chris Vandomelen wrote : socket_select(0x7fff, $fd_set, 0, 0, 0, 0); we can add a support function which return's the php_socket-socket integer. Glad someone came up with this. Since socket_select() always wants highest +1, couldn't this be implemented into socket_select() to go through all socket sets and get the number itself ? Or are there good reasons to let the user specify the value on its own ? In theory, the user isn't going to be specifying sockets that aren't accessible as resources. The best way around this (IMHO) is to define a php_fd_set something like: struct php_fd_set { fd_set the_set; intmax_fd; }; Btw, is this really enough information ? Consider this: You use FD_SET() to add a socket to the set (you just bump_up max_fd if socket max_Fd) But when using FD_CLR() to remove a socket how do we know which socket in this set has the highest number now and whats the number anyway (beside 42) then ? Seems like we need a list for every set containing the current socket numbers in the set (if I'm not totally wrong :) because AFAIK if you don't keep a list of the numbers of a set without brute force you can't retrieve the list. Maybe we should just stick to the single function which in addition returns the handle of the socket itself. - Markus -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] cvs socket extension
On Mon, Jul 23, 2001 at 07:20:34AM -0700, Chris Vandomelen wrote : socket_select(0x7fff, $fd_set, 0, 0, 0, 0); we can add a support function which return's the php_socket-socket integer. Glad someone came up with this. Since socket_select() always wants highest +1, couldn't this be implemented into socket_select() to go through all socket sets and get the number itself ? Or are there good reasons to let the user specify the value on its own ? In theory, the user isn't going to be specifying sockets that aren't accessible as resources. The best way around this (IMHO) is to define a php_fd_set something like: struct php_fd_set { fd_set the_set; intmax_fd; }; Btw, is this really enough information ? Consider this: You use FD_SET() to add a socket to the set (you just bump_up max_fd if socket max_Fd) But when using FD_CLR() to remove a socket how do we know which socket in this set has the highest number now and whats the number anyway (beside 42) then ? If one is removed, it doesn't hurt the end result. If one is added outside of max_fd and max_fd isn't raised appropriately, you run into trouble. Chris -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] cvs socket extension
Just for curiosity, did you considered implementing poll instead of select? You would not have to worry about specifying max_fd - 1. -Jason - Original Message - From: Chris Vandomelen [EMAIL PROTECTED] To: Markus Fischer [EMAIL PROTECTED] Cc: Daniel Beulshausen [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Monday, July 23, 2001 9:20 AM Subject: Re: [PHP-DEV] cvs socket extension socket_select(0x7fff, $fd_set, 0, 0, 0, 0); we can add a support function which return's the php_socket-socket integer. Glad someone came up with this. Since socket_select() always wants highest +1, couldn't this be implemented into socket_select() to go through all socket sets and get the number itself ? Or are there good reasons to let the user specify the value on its own ? In theory, the user isn't going to be specifying sockets that aren't accessible as resources. The best way around this (IMHO) is to define a php_fd_set something like: struct php_fd_set { fd_set the_set; intmax_fd; }; Then, whenver someone calls fd_set() or fd_zero(), change php_fd_set.max_fd appropriately as well as updating php_fd_set.the_set, and in socket_select(), check all of the max_fd values. Removing the first arg to socket_select(), if that's implemented, wouldn't be a bad idea either. Chris -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] cvs socket extension
On Mon, Jul 23, 2001 at 11:15:49PM +0200, Stig Venaas wrote : On Mon, Jul 23, 2001 at 05:16:13PM +0200, Markus Fischer wrote: On Mon, Jul 23, 2001 at 07:20:34AM -0700, Chris Vandomelen wrote : Since socket_select() always wants highest +1, couldn't this be implemented into socket_select() to go through all socket sets and get the number itself ? Why all sets? Isn't it enough to use max for the set that got passed to socket_select()? The best way around this (IMHO) is to define a php_fd_set something like: struct php_fd_set { fd_set the_set; intmax_fd; }; Btw, is this really enough information ? Yes, that's my doubt as well, I'm not sure how much of a problem it is though. Consider this: You use FD_SET() to add a socket to the set (you just bump_up max_fd if socket max_Fd) But when using FD_CLR() to remove a socket how do we know which socket in this set has the highest number now and whats the number anyway (beside 42) then ? Seems like we need a list for every set containing the current socket numbers in the set (if I'm not totally wrong :) because AFAIK if you don't keep a list of the numbers of a set without brute force you can't retrieve the list. In order to be portable we can't inspect the actual bits in the set I think, so the only way I see is to have a list of the numbers. So for every call to socket_fd_set(), you add to the list, and in socket_fd_clear() you remove. In order to not look for max every time you call select, you might also store the max somewhere maybe. I think you should have one such list per set, and create an empty list in socket_fd_alloc(). Chris mentioned something that its not needed to restore the last highest value for the max_fd if you drop the current highest one. This makes me wondering why we not ever pass something like 0x to select() [of course there is some legal reason not to do this, i'm just curious now]. One the other hand, Daniel [afaik??] suggested to let the user retrieve the handle id for a socket and calculate the hightest value on its own. Something like $fd = socket_get_fd( $socket); comes into my mind. The first one would be more nice for the users while the later is much less programming effort :-) I'm just wondering if there can be ever any drawback if we don't let the user specify the first parameter to the select() call. As I'm not an expert I can't tell. regards, Markus -- Markus Fischer, http://guru.josefine.at/~mfischer/ EMail: [EMAIL PROTECTED] PGP Public Key: http://guru.josefine.at/~mfischer/C2272BD0.asc PGP Fingerprint: D3B0 DD4F E12B F911 3CE1 C2B5 D674 B445 C227 2BD0 -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] cvs socket extension
On Mon, Jul 23, 2001 at 11:57:44PM +0200, Markus Fischer wrote: On Mon, Jul 23, 2001 at 11:15:49PM +0200, Stig Venaas wrote : Chris mentioned something that its not needed to restore the last highest value for the max_fd if you drop the current highest one. I agree, it would only be for efficiency. I think now that the best solution is to just store the max. If clear.. is called with the current max, we can start at max and going downwards we can do FD_ISSET on each number until we find something that is set. Then we have the new max. This makes me wondering why we not ever pass something like 0x to select() [of course there is some legal reason not to do this, i'm just curious now]. Maybe, but I don't like it. Are you sure there are may not be bad things happening if the number is outside the size of the set? One the other hand, Daniel [afaik??] suggested to let the user retrieve the handle id for a socket and calculate the hightest value on its own. Something like $fd = socket_get_fd( $socket); comes into my mind. The first one would be more nice for the users while the later is much less programming effort :-) Yes, I think we should be nice to the users though (: There's less time wasted by doing it once in C than having many PHP programmers doing it over and over again... I'm just wondering if there can be ever any drawback if we don't let the user specify the first parameter to the select() call. As I'm not an expert I can't tell. I'm no expert, but I really can't see why it's needed (: Stig -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] cvs socket extension
On Mon, Jul 23, 2001 at 11:15:49PM +0200, Stig Venaas wrote : On Mon, Jul 23, 2001 at 05:16:13PM +0200, Markus Fischer wrote: On Mon, Jul 23, 2001 at 07:20:34AM -0700, Chris Vandomelen wrote : Since socket_select() always wants highest +1, couldn't this be implemented into socket_select() to go through all socket sets and get the number itself ? Why all sets? Isn't it enough to use max for the set that got passed to socket_select()? But you can pass three different sets to socket_select(); thats what I meant with 'go through all socket sets'. - Markus -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] cvs socket extension
On Mon, Jul 23, 2001 at 11:57:44PM +0200, Markus Fischer wrote: On Mon, Jul 23, 2001 at 11:15:49PM +0200, Stig Venaas wrote : Chris mentioned something that its not needed to restore the last highest value for the max_fd if you drop the current highest one. I agree, it would only be for efficiency. I think now that the best solution is to just store the max. If clear.. is called with the current max, we can start at max and going downwards we can do FD_ISSET on each number until we find something that is set. Then we have the new max. You can store the max, but it's not necessary to decrease it if someone does FD_CLR() on a FD in the set. The only negative effect specifying a larger value to select() has is extra loops in kernel space. This makes me wondering why we not ever pass something like 0x to select() [of course there is some legal reason not to do this, i'm just curious now]. Maybe, but I don't like it. Are you sure there are may not be bad things happening if the number is outside the size of the set? See above. BTW, you never specify 0x to select() anyway. 0x = (int) -1. :) One the other hand, Daniel [afaik??] suggested to let the user retrieve the handle id for a socket and calculate the hightest value on its own. Something like $fd = socket_get_fd( $socket); comes into my mind. The first one would be more nice for the users while the later is much less programming effort :-) Yes, I think we should be nice to the users though (: There's less time wasted by doing it once in C than having many PHP programmers doing it over and over again... I can't see why a user would ever need access to the actual file descriptor returned. I'm just wondering if there can be ever any drawback if we don't let the user specify the first parameter to the select() call. As I'm not an expert I can't tell. I'm no expert, but I really can't see why it's needed (: Nor do i. :) Chris -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] cvs socket extension
On Mon, 23 Jul 2001, Jason Greene wrote: Just for curiosity, did you considered implementing poll instead of select? You would not have to worry about specifying max_fd - 1. -Jason I had considered poll. But it's a bit more of a hassle, and it's not avaliable everywhere (AFAIK). Chris -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] cvs socket extension
On Mon, Jul 23, 2001 at 07:50:22PM -0700, Chris Vandomelen wrote : On Mon, Jul 23, 2001 at 11:57:44PM +0200, Markus Fischer wrote: On Mon, Jul 23, 2001 at 11:15:49PM +0200, Stig Venaas wrote : Chris mentioned something that its not needed to restore the last highest value for the max_fd if you drop the current highest one. I agree, it would only be for efficiency. I think now that the best solution is to just store the max. If clear.. is called with the current max, we can start at max and going downwards we can do FD_ISSET on each number until we find something that is set. Then we have the new max. You can store the max, but it's not necessary to decrease it if someone does FD_CLR() on a FD in the set. The only negative effect specifying a larger value to select() has is extra loops in kernel space. This makes me wondering why we not ever pass something like 0x to select() [of course there is some legal reason not to do this, i'm just curious now]. Maybe, but I don't like it. Are you sure there are may not be bad things happening if the number is outside the size of the set? See above. BTW, you never specify 0x to select() anyway. 0x = (int) -1. :) One the other hand, Daniel [afaik??] suggested to let the user retrieve the handle id for a socket and calculate the hightest value on its own. Something like $fd = socket_get_fd( $socket); comes into my mind. The first one would be more nice for the users while the later is much less programming effort :-) Yes, I think we should be nice to the users though (: There's less time wasted by doing it once in C than having many PHP programmers doing it over and over again... I can't see why a user would ever need access to the actual file descriptor returned. I'm just wondering if there can be ever any drawback if we don't let the user specify the first parameter to the select() call. As I'm not an expert I can't tell. I'm no expert, but I really can't see why it's needed (: Nor do i. :) Great :-) So we're seeing this getting implemented soon ? Volunteers, anyone ? :-)) - Markus -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]