select/poll for sockets in kernel space

John Baldwin jhb at freebsd.org
Tue May 25 15:18:41 UTC 2010


On Tuesday 25 May 2010 5:02:35 am Dmitry Krivenok wrote:
> Hello Hackers!
> 
> I'm developing a module for FreeBSD-8 and encountered the problem with
> polling sockets.
> I know that FreeBSD-8 kernel provides 3 interfaces for polling
> (kern/sys_generic.c):
> 1) kern_select
> 2) poll
> 3) selsocket
> 
> I cannot use first two interfaces because I have an array of sockets
> (struct socket) created using socreate, i.e. I don't have file
> descriptors.
> I also cannot use selsocket because it doesn't tell me which events
> fired and takes only one socket (but I have an array of sockets).
> 
> The problem is that the module I'm developing should work on
> unmodified FreeBSD-8 kernel.
> So I cannot just add new functionality suitable for my task in
> kern/sys_generic.c.
> I also cannot implement such functionality in the module itself
> because select/poll implementation is hidden and only limited number
> of interfaces is available to the rest
> of the kernel (which is generally good, but not in my case :)).
> 
> Is it possible to solve my problem using existing kernel functionality?
> Any suggestions are welcome!
> 
> Thanks in advance!
> 
> P.S.
> I know about kqueue, but I have to use select/poll is this task.

Why do you have to use select/poll?  If these are dedicated sockets that you 
create internally, then the right thing to do is probably to install your own 
upcalls that get called when data for a socket arrives.  This is what the in-
kernel NFS client does to handle incoming data.

-- 
John Baldwin


More information about the freebsd-hackers mailing list