From 33efd30b33511dc6aa7b598e269b88de7441e7a9 Mon Sep 17 00:00:00 2001 From: Daniel De Graaf Date: Sat, 19 Jun 2010 20:58:57 -0400 Subject: Change ThreadSignalSocket to EventHandler to avoid calling recv() on an eventfd, which does not work --- src/threadengines/threadengine_pthread.cpp | 57 +++++++++++++++++++----------- 1 file changed, 36 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/threadengines/threadengine_pthread.cpp b/src/threadengines/threadengine_pthread.cpp index f2640b5ae..29a4b1a96 100644 --- a/src/threadengines/threadengine_pthread.cpp +++ b/src/threadengines/threadengine_pthread.cpp @@ -61,11 +61,15 @@ void ThreadData::FreeThread(Thread* thread) #ifdef HAS_EVENTFD #include -class ThreadSignalSocket : public BufferedSocket +class ThreadSignalSocket : public EventHandler { SocketThread* parent; public: - ThreadSignalSocket(SocketThread* p, int newfd) : BufferedSocket(newfd), parent(p) {} + ThreadSignalSocket(SocketThread* p, int newfd) : parent(p) + { + SetFd(newfd); + ServerInstance->SE->AddFd(this, FD_WANT_FAST_READ | FD_WANT_NO_WRITE); + } ~ThreadSignalSocket() { @@ -76,15 +80,18 @@ class ThreadSignalSocket : public BufferedSocket eventfd_write(fd, 1); } - void OnDataReady() - { - recvq.clear(); - parent->OnNotify(); - } - - void OnError(BufferedSocketError) + void HandleEvent(EventType et, int errornum) { - ServerInstance->GlobalCulls.AddItem(this); + if (et == EVENT_READ) + { + eventfd_t dummy; + eventfd_read(fd, &dummy); + parent->OnNotify(); + } + else + { + ServerInstance->GlobalCulls.AddItem(this); + } } }; @@ -97,13 +104,18 @@ SocketThread::SocketThread() } #else -class ThreadSignalSocket : public BufferedSocket +class ThreadSignalSocket : public EventHandler { SocketThread* parent; int send_fd; public: ThreadSignalSocket(SocketThread* p, int recvfd, int sendfd) : - BufferedSocket(recvfd), parent(p), send_fd(sendfd) {} + parent(p), send_fd(sendfd) + { + SetFd(recvfd); + ServerInstance->SE->NonBlocking(fd); + ServerInstance->SE->AddFd(this, FD_WANT_FAST_READ | FD_WANT_NO_WRITE); + } ~ThreadSignalSocket() { @@ -112,19 +124,22 @@ class ThreadSignalSocket : public BufferedSocket void Notify() { - char dummy = '*'; + static const char dummy = '*'; write(send_fd, &dummy, 1); } - void OnDataReady() - { - recvq.clear(); - parent->OnNotify(); - } - - void OnError(BufferedSocketError) + void HandleEvent(EventType et, int errornum) { - ServerInstance->GlobalCulls.AddItem(this); + if (et == EVENT_READ) + { + char dummy[128]; + read(fd, dummy, 128); + parent->OnNotify(); + } + else + { + ServerInstance->GlobalCulls.AddItem(this); + } } }; -- cgit v1.2.3