inspircd

A modular C++ IRC daemon (ircd). https://www.inspircd.org/
Log | Files | Refs | README

commit 0c992c5a3d6b30a6b14adf3181bf0b1e1fdeab48
parent 044fa999680888267e07dc7b69028b18efbac818
Author: Peter Powell <petpow@saberuk.com>
Date:   Fri,  3 May 2019 15:37:25 +0100

Work around NetBSD's EV_SET using intptr_t instead of void*.

Reported by @ensra.

Diffstat:
Msrc/socketengines/socketengine_kqueue.cpp | 23+++++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/src/socketengines/socketengine_kqueue.cpp b/src/socketengines/socketengine_kqueue.cpp @@ -39,6 +39,20 @@ namespace /** Pending changes */ std::vector<struct kevent> changelist(8); + +#ifdef __NetBSD__ + inline intptr_t udata_cast(EventHandler* eh) + { + // On NetBSD the last parameter of EV_SET is intptr_t. + return reinterpret_cast<intptr_t>(eh); + } +#else + inline void* udata_cast(EventHandler* eh) + { + // On other platforms the last parameter of EV_SET is void*. + return static_cast<void*>(eh); + } +#endif } /** Initialize the kqueue engine @@ -87,7 +101,7 @@ bool SocketEngine::AddFd(EventHandler* eh, int event_mask) // We always want to read from the socket... struct kevent* ke = GetChangeKE(); - EV_SET(ke, fd, EVFILT_READ, EV_ADD, 0, 0, static_cast<void*>(eh)); + EV_SET(ke, fd, EVFILT_READ, EV_ADD, 0, 0, udata_cast(eh)); ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "New file descriptor: %d", fd); @@ -128,7 +142,7 @@ void SocketEngine::OnSetEvent(EventHandler* eh, int old_mask, int new_mask) { // new poll-style write struct kevent* ke = GetChangeKE(); - EV_SET(ke, eh->GetFd(), EVFILT_WRITE, EV_ADD, 0, 0, static_cast<void*>(eh)); + EV_SET(ke, eh->GetFd(), EVFILT_WRITE, EV_ADD, 0, 0, udata_cast(eh)); } else if ((old_mask & FD_WANT_POLL_WRITE) && !(new_mask & FD_WANT_POLL_WRITE)) { @@ -139,7 +153,7 @@ void SocketEngine::OnSetEvent(EventHandler* eh, int old_mask, int new_mask) if ((new_mask & (FD_WANT_FAST_WRITE | FD_WANT_SINGLE_WRITE)) && !(old_mask & (FD_WANT_FAST_WRITE | FD_WANT_SINGLE_WRITE))) { struct kevent* ke = GetChangeKE(); - EV_SET(ke, eh->GetFd(), EVFILT_WRITE, EV_ADD | EV_ONESHOT, 0, 0, static_cast<void*>(eh)); + EV_SET(ke, eh->GetFd(), EVFILT_WRITE, EV_ADD | EV_ONESHOT, 0, 0, udata_cast(eh)); } } @@ -160,8 +174,9 @@ int SocketEngine::DispatchEvents() for (int j = 0; j < i; j++) { + // This can't be a static_cast because udata is intptr_t on NetBSD. struct kevent& kev = ke_list[j]; - EventHandler* eh = static_cast<EventHandler*>(kev.udata); + EventHandler* eh = reinterpret_cast<EventHandler*>(kev.udata); if (!eh) continue;