Reputation: 27631
I have a driver, which handles several TCP connections.
Is there a way to perform something similar to user space application api's select/poll()/epoll() in kernel given a list of struct sock
's?
Thanks
Upvotes: 7
Views: 1208
Reputation: 6786
You may want to write your own custom sk_buff
handler, which calls the kernel_select()
that tries to lock the semaphore and does a blocking wait when the socket is open.
Not sure if you have already gone through this link Simulate effect of select()
and poll()
in kernel socket programming
Upvotes: 6
Reputation: 7625
On the kernel side it's easy to avoid using sys_epoll()
interface outright. After all, you've got a direct access to kernel objects, no need to jump through hoops.
Each file
object, sockets included, "overrides" a poll method in its file_operations
"vtable". You can simply loop around all your sockets, calling ->poll()
on each of them and yielding periodically or when there's no data available.
If the sockets are fairly high traffic, you won't need anything more than this.
A note on the API:
poll()
method requires a poll_table()
argument, however if you do not intend to wait on it, it can safely be initialized to null:
poll_table pt;
init_poll_funcptr(&pt, NULL);
...
// struct socket *sk;
...
unsigned event_mask = sk->ops->poll(sk->file, sk, &pt);
If you do want to wait, just play around with the callback set into poll_table
by init_poll_funcptr()
.
Upvotes: 2