[libdispatch-dev] dispatch source for multi-client sockets
Mikkel Fahnøe Jørgensen
mikkelfj at gmail.com
Tue Sep 22 03:15:13 PDT 2009
How does one create a dispatch source that responds to multiple
connections on the same socket, that is, listening on a socket with a
backlog larger than 1?
In the online doc it seems that you should have a connected socket to
read from, the same way as reading from a file. But documentation also
says you need a socket returned from listen().
So where does the accept() call fit into this? Specifically it would
be nice to avoid blocking on accept() before creating a read source.
I found this echo server example based on kqueue events which seems to
receive a read event. First the handler will accept the socket, then
do normal read processing. Is this also how it should work with
libdispatch, and if so, what about other platforms.
And how about similar event sources for DNS lookup?
Libevent did a bit of work on these issues, and I see it has already
been mentioned on this mailing list.
Related: I don't see any examples of custom event sources - but I
thought that might also be a way to schedule client handlers?
Finally, what is the policy on busy loops and locking operations? One
could for example push a blocking socket accept() call onto a queue,
but this consumes a thread from a thread pool that is designed to
reflect number of cpus not number of long running tasks. Alternatively
one could create a dedicated thread for this purpose, but that doesn't
seem very elegant.
More information about the libdispatch-dev