Hurd: implement selectable_fd.#1565
Conversation
|
This adds an extra move of the packet data through a pipe, which seems... suboptimal. Is there a way in Hurd to do a Is there a way to have an "event" descriptor that can be selected on and that can be poked to trigger a select wakeup? (Linux and Windows have that, and they're used in libpcap.) |
Yes, I know, we already discused this in the hurd list: https://www.mail-archive.com/bug-hurd@gnu.org/msg37636.html
None of those two, as far as I know. From my current knowledge, I can only think on two solutions:
int
pcap_get_selectable_fd(pcap_t *p)
{
if (!p->selectable_fd) {
pcap_init_selectable_fd();
}
return (p->selectable_fd);
}and that Would you accept something like this? |
Not directly with a mach port, but instead of writing the whole packet to the pipe, we could put the packet in a queue and just write one dumb byte to the pipe, the read side would get the packet from the queue. |
I was thinking more of something like a Linux eventfd object, which doesn't have a buffer that can fill up (as pipes do). The limit on the number of events that can be posted on an eventfd object is the size of its counter, which is a 64-bit unsigned number. A call that can block waiting on a descriptor or a Mach port would also work, such as |
|
One can use a mach port set to be able to receive messages from either of several mach ports included in the set. |
But what if you have an event loop that would have to wait for events both on descriptors (pipes, sockets, etc.) and on Mach parts? (That's why Apple added |
One can use |
Then we should add a Hurd-specific |
|
Or allocate a Hurd fd for the Mach port with |
|
It would need adding |
Some *BSDs also have or had bugs in Speaking of handling packet capture in event loops, the |
Yes, mach_msg with a zero timeout will do a single poll and not block. |
* Implement a message queue using STAILQ to pass packets from the Mach receive thread to pcap_read_hurd(). * The queue and mutex are per-handle, initialized on activate and cleaned up on teardown. * The pipe remains used only for signaling readiness between threads.
|
@guyharris @sthibaul I committed some changes to make the messages go through per-handle local queues instead of pipes. Pipes are still used but only for signalling readiness. After this changes, the I think it's the best thing we can do right now. Alternatives are: either making changes in gnumach to make it notify readiness, or implement something similar to |
This PR implements the
selectable_fdfeature for the Hurd. This is neededby some clients like dhcpcd.
In this patch, the approach is to make the data pass through a pipe,
which read end is going to be the
selectable_fd. When capture starts, anew thread gets packets from gnumach BPF and pushes them to the pipe.