-
-
Notifications
You must be signed in to change notification settings - Fork 498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add kqueue support for Darwin/BSD #35
Comments
Hi - I began taking a look at this since it looked like a reasonably well isolated task, and had a couple questions about your vision for the polling system. Currently, the Since some posix platforms will want to use different polling implementations (kqueue, epoll, etc), do you imagine creating a polling api that would be implemented for those backends? Maybe you have another approach in mind? Let me know and I can either try to assist or just stay out of the way until it's clearer how to proceed 😄 |
Sorry I didn't respond earlier. Thanks for your interest in contributing to nng! So I think you can look at the posix_pollq_poll.c to see how to write a poller. There is a common API. I'm not 100% certain that it is fully adequate, but if you find you need something that the core doesn't provide, let me know and we'll work it through. Fundamentally, you have to implement these functions: nni_posix_pollq_add() - adds a pollq node to the poller When events that have been armed occur on the file descriptor associated with the node, you need to set the "revents" member and call the user supplied callback (cb). Reading the posix_pollq_poll.c code should help you see what needs to be done. The way I'd like to see the use of kqueue and the like enabled is via CMake tests, for example look at how we detect the availability of clock_gettime() in the top level CMakeLists.txt. This needs to enable a different NNG_USE_POSIX_POLLQ_KQUEUE variable, and the setting of the current in posix_config.h needs to be made conditional, much like the clock definitions above it are done. I had btw started doing this for epoll(), but set it aside for a bit. I seem to recall that I did need to do something different there, and that I had some additional state requirements that had to be added to pollq_node, but I don't remember exactly what they were. |
Oh, you may need to implement the functions nni_posix_pollq_sysinit() and nni_posix_pollq_sysfini(). See the posix_pollq.h header file -- that is actually intended to "formally" define the polling API for the backend implementations on UNIX-like systems. |
Got it. It seems a little strange to depend on Otherwise, understood that posix_pollq.h is meant to be the general api for polling on posix systems 👍 |
So the reason we rely on those symbols (POLLIN, POLLOUT, etc.) is that they are required to be defined on POSIX systems. We could have invented our own symbols for this, but there seemed to be little point in doing so, and by using the symbols that are well known, we actually can simplify some of the backends. (For example, the poll(), epoll(), and /dev/poll implementations all use the same symbols, or symbols that are guaranteed to be numerically equivalent.) kqueue is the odd one our here, I think, since its EVFILT stuff is quite a bit different. |
Fixed in 7849fd2 |
We would like to have kqueue based polling for improved scalability.
The text was updated successfully, but these errors were encountered: