Can someone explain why ext/sockets and also stream socket functions care about FD_SETSIZE?
define PHP_SAFE_FD_SET(fd, set) do { if (fd < FD_SETSIZE) FD_SET(fd, set); } while(0)
On Linux, it's not a hard limitation imposed by the kernel. It's configurable via sysctl.
-Andrei
Can someone explain why ext/sockets and also stream socket functions care
about FD_SETSIZE?
They care, because they use the select(2) syscall, which cares about FD_SETSIZE.
Robin Burchell wrote:
Can someone explain why ext/sockets and also stream socket functions care
about FD_SETSIZE?They care, because they use the select(2) syscall, which cares about FD_SETSIZE.
select(2) itself can handle more fildes than FD_SETSIZE on Linux at least.
Moriyoshi
Hi,
That's the reason why I started writing an ext for PHP that would
implement epoll() on linux, and stuff-with-ws2 on Win32.
However I don't mind making this a patch to the stream ext.
Basically I get the following functions:
consts:
STREAM_POLL_IN (read)
STREAM_POLL_OUT (write)
STREAM_POLL_ONESHOT
(other options exists on epoll, but are not portable. Some, like
"oneshot" can easily be emulated)
functions:
resource stream_poll_create()
bool stream_poll_destroy(resource $poll)
array stream_poll_wait(resource $poll, int $timeout,int $maxevents = -1)
bool stream_poll_add(resource $poll, stream $socket, int $wait_flags)
bool stream_poll_mod(resource $poll, stream $socket, int $wait_flags)
bool stream_poll_del(resource $poll, stream $socket)
The goal is to use epoll() on linux, weird win32 stuff on win32 (thingie
that converts socket to handler, then allows to use waitmultiple on
that), kqueue on BSD and fallback to select on all other operating
systems so those functions can be used anywhere.
Anyway I was initially planning to use that internally, then maybe
release it on pecl, it makes more sense to be inside ext/stream (I
guess), so if anyone want to see it faster than that, why not.
This can also be made OO, however the current stream ext has nothing OO,
so I'm not sure it would make any sense.
Anyway feedback about this is welcome, I've been wanting to write this
for pinetd (those who heared about a PHP DNS Daemon should know what I
mean) as using select() can become a problem when you want to handle a
lot of clients.
I am a bit demotivated, however if there is interest into this, or even
if it can make it into ext/stream, I would be more than happy to
finish/release that.
Mark
Le vendredi 20 février 2009 à 12:02 +0900, Moriyoshi Koizumi a écrit :
Robin Burchell wrote:
Can someone explain why ext/sockets and also stream socket functions care
about FD_SETSIZE?They care, because they use the select(2) syscall, which cares about FD_SETSIZE.
select(2) itself can handle more fildes than FD_SETSIZE on Linux at least.
Moriyoshi
That's because struct fd_set, which is manipulated by FD_SET, is a
struct that contains a fixed-size array.
Moriyoshi
Andrei Zmievski wrote:
Can someone explain why ext/sockets and also stream socket functions
care about FD_SETSIZE?define PHP_SAFE_FD_SET(fd, set) do { if (fd < FD_SETSIZE) FD_SET(fd,
set); } while(0)
On Linux, it's not a hard limitation imposed by the kernel. It's
configurable via sysctl.-Andrei