Using the select () / poll () function in a device driver

I have a driver that handles multiple TCP connections.

Is there a way to execute something similar to api select / poll () / epoll () user space application in the kernel, given a list of struct sock 's?

thanks

+8
linux linux-kernel
source share
2 answers

You might want to write your own custom sk_buff handler, which calls kernel_select() , which tries to block the semaphore and blocks waiting when the socket is opened.

Not sure if you've already passed this link. Simulate the effect of select() and poll() in programming a kernel socket

+6
source share

On the kernel side, it is easy to avoid using the sys_epoll() interface. In the end, you have direct access to the kernel objects, there is no need to jump through hoops.

Each file object, including sockets, "redefines" the polling method in its file_operations "vtable". You can simply bypass all your sockets by calling ->poll() for each of them and periodically displaying or when there is no data available.

If sockets have fairly high traffic, you don’t need anything else.

API Note:

poll() requires the poll_table() argument, however, if you are not going to wait for it, you can safely initialize it to zero:

 poll_table pt; init_poll_funcptr(&pt, NULL); ... // struct socket *sk; ... unsigned event_mask = sk->ops->poll(sk->file, sk, &pt); 

If you want to wait, just play around with the callback set in poll_table to init_poll_funcptr() .

+2
source share

All Articles