سؤال

Does anybody know equivalent for NETLINK Sockets API for MAC OS X ? I am trying to port Linux application to MAC OS X and I couldn’t find anything similar in MACOS.

I need to provide asynchronous access to the network adapter in my application.

Polling network adapter about configuration changes etc every certain amount of seconds is not convenient solution for me. NETLINK Socket API game me way to receive notification only when something interesting happened.

I know that NETLINK is Linux specific thing to communicate between Linux kernel and user space, but maybe there is exist something like NETLINK under MACOS.

I see the the only tool to communicate with kernel – sysctl()

Does anybody have any info?

هل كانت مفيدة؟

المحلول

You can use the kernel control architecture which is documented in the NKE section of their docs that OSX provides for that reason.

نصائح أخرى

The traditional way of doing this is to wait for events on the socket using select/poll/epoll/kqueue. See this answer for what is best on what platform: select vs poll vs epoll.

Alternatively, spawn a new thread for each connection and use blocking socket reads. Though, history have taught us that this is less scalable than non-blocking I/O via select/poll/kqueue. This was the way most people originally wrote network servers in the 1990s. Depending on your coding style, blocking I/O + threads may be easier to work with.

Note that contrary to its name, epoll is not polling.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top