Add kqueue support for macOS/BSD#735
Open
deepdiver-997 wants to merge 1 commit intochenshuo:masterfrom
Open
Conversation
Implemented KQueuePoller to replace EPollPoller on macOS/BSD platforms. Key changes: - New KQueuePoller class using kqueue() syscall for IO multiplexing - EventLoop now uses socketpair instead of eventfd on macOS - TimerQueue uses polling approach instead of timerfd on macOS - Fixed bindOrDie to use correct address length for IPv4 - Various compatibility fixes for macOS (byte order, threading, etc.) KQueuePoller features: - Uses kqueue()/kevent() for event registration and waiting - EVFILT_READ/EVFILT_WRITE for read/write events - EVFILT_EXCEPT for exception handling - Edge-triggered semantics compatible with muduo's level-triggered design Tested with: - timerqueue_unittest - eventloopthread_unittest - eventloopthreadpool_unittest - TcpServer binding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add kqueue support for macOS/BSD platforms, enabling muduo network library to work on Apple macOS and other BSD-derived systems.
Motivation
muduo currently only supports epoll on Linux. macOS users cannot build or use muduo due to missing:
Changes
New Files
muduo/net/poller/KQueuePoller.cc- KQueue implementationmuduo/net/poller/KQueuePoller.h- KQueue headerPlatform Abstraction
muduo/net/EventLoop.cc- Uses socketpair instead of eventfd on macOSmuduo/net/TimerQueue.cc- Uses polling instead of timerfd on macOSmuduo/net/SocketsOps.cc- Fixed bindOrDie address length bugCompatibility Fixes
muduo/net/Endian.h- Added macOS byte order macrosmuduo/base/Mutex.h- macOS-compatible assert_perror_failTesting
Technical Details
KQueuePoller uses macOS/BSD kqueue syscall:
kqueue()creates kernel event queuekevent()registers/changes/removes events and waits for eventsEVFILT_READ/EVFILT_WRITEmap to POLLIN/POLLOUTBreaking Changes
None - fully backward compatible, Linux epoll path unchanged.