From e2af2347fc035d702e45f12e772223a8d578410d Mon Sep 17 00:00:00 2001 From: danieldg Date: Mon, 21 Sep 2009 13:26:31 +0000 Subject: Create StreamSocket for IO hooking implementation Fixes the SSL SendQ bug Removes duplicate code between User and BufferedSocket Simplify SSL module API Simplify EventHandler API (Readable/Writeable moved to SE) Add hook for culled objects to invoke callbacks prior to destructor Replace SocketCull with GlobalCull now that sockets can close themselves Shorten common case of user read/parse/write path: User::Write is now zero-copy up to syscall/SSL invocation User::Read has only two copy/scan passes from read() to ProcessCommand git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11752 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/threadengines/threadengine_pthread.cpp | 33 +++++++++++++++--------------- src/threadengines/threadengine_win32.cpp | 17 ++++++--------- 2 files changed, 23 insertions(+), 27 deletions(-) (limited to 'src/threadengines') diff --git a/src/threadengines/threadengine_pthread.cpp b/src/threadengines/threadengine_pthread.cpp index 6e32634c5..a4a47f8fa 100644 --- a/src/threadengines/threadengine_pthread.cpp +++ b/src/threadengines/threadengine_pthread.cpp @@ -65,8 +65,7 @@ class ThreadSignalSocket : public BufferedSocket { SocketThread* parent; public: - ThreadSignalSocket(SocketThread* p, InspIRCd* SI, int newfd) : - BufferedSocket(SI, newfd, const_cast("0.0.0.0")), parent(p) {} + ThreadSignalSocket(SocketThread* p, int newfd) : BufferedSocket(newfd), parent(p) {} ~ThreadSignalSocket() { @@ -77,13 +76,14 @@ class ThreadSignalSocket : public BufferedSocket eventfd_write(fd, 1); } - virtual bool OnDataReady() + void OnDataReady() { - eventfd_t data; - if (eventfd_read(fd, &data)) - return false; + recvq.clear(); parent->OnNotify(); - return true; + } + + void OnError(BufferedSocketError) + { } }; @@ -92,7 +92,7 @@ SocketThread::SocketThread(InspIRCd* SI) int fd = eventfd(0, O_NONBLOCK); if (fd < 0) throw new CoreException("Could not create pipe " + std::string(strerror(errno))); - signal.sock = new ThreadSignalSocket(this, SI, fd); + signal.sock = new ThreadSignalSocket(this, fd); } #else @@ -101,8 +101,8 @@ class ThreadSignalSocket : public BufferedSocket SocketThread* parent; int send_fd; public: - ThreadSignalSocket(SocketThread* p, InspIRCd* SI, int recvfd, int sendfd) : - BufferedSocket(SI, recvfd, const_cast("0.0.0.0")), parent(p), send_fd(sendfd) {} + ThreadSignalSocket(SocketThread* p, int recvfd, int sendfd) : + BufferedSocket(recvfd), parent(p), send_fd(sendfd) {} ~ThreadSignalSocket() { @@ -115,13 +115,14 @@ class ThreadSignalSocket : public BufferedSocket write(send_fd, &dummy, 1); } - virtual bool OnDataReady() + void OnDataReady() { - char data; - if (read(this->fd, &data, 1) <= 0) - return false; + recvq.clear(); parent->OnNotify(); - return true; + } + + void OnError(BufferedSocketError) + { } }; @@ -130,7 +131,7 @@ SocketThread::SocketThread(InspIRCd* SI) int fds[2]; if (pipe(fds)) throw new CoreException("Could not create pipe " + std::string(strerror(errno))); - signal.sock = new ThreadSignalSocket(this, SI, fds[0], fds[1]); + signal.sock = new ThreadSignalSocket(this, fds[0], fds[1]); } #endif diff --git a/src/threadengines/threadengine_win32.cpp b/src/threadengines/threadengine_win32.cpp index 5c62b5081..fab75699e 100644 --- a/src/threadengines/threadengine_win32.cpp +++ b/src/threadengines/threadengine_win32.cpp @@ -55,20 +55,15 @@ class ThreadSignalSocket : public BufferedSocket { SocketThread* parent; public: - ThreadSignalSocket(SocketThread* t, InspIRCd* SI, int newfd, const char* ip) - : BufferedSocket(SI, newfd, ip), parent(t) + ThreadSignalSocket(SocketThread* t, int newfd) + : BufferedSocket(newfd), parent(t) { } - virtual bool OnDataReady() + void OnDataReady() { - char data = 0; - if (ServerInstance->SE->Recv(this, &data, 1, 0) > 0) - { - parent->OnNotify(); - return true; - } - return false; + recvq.clear(); + parent->OnNotify(); } }; @@ -92,7 +87,7 @@ SocketThread::SocketThread(InspIRCd* SI) int nfd = accept(listenFD); if (nfd < 0) throw CoreException("Could not create ITC pipe"); - new ThreadSignalSocket(parent, ServerInstance, nfd, "127.0.0.1"); + new ThreadSignalSocket(parent, nfd); closesocket(listenFD); SI->SE->Blocking(connFD); -- cgit v1.2.3