From 09b802d5e94b71318e3b49f2d35554438efc5331 Mon Sep 17 00:00:00 2001 From: danieldg Date: Wed, 2 Sep 2009 00:46:58 +0000 Subject: ThreadWindows: Remove ThreadSignalListener and connect the socket right away git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11617 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/socketengine.cpp | 2 +- src/threadengines/threadengine_win32.cpp | 56 ++++++++++---------------------- 2 files changed, 18 insertions(+), 40 deletions(-) diff --git a/src/socketengine.cpp b/src/socketengine.cpp index 9d54e8b66..af2f1b169 100644 --- a/src/socketengine.cpp +++ b/src/socketengine.cpp @@ -188,7 +188,7 @@ int SocketEngine::Blocking(int fd) return ioctlsocket(fd, FIONBIO, &opt); #else int flags = fcntl(fd, F_GETFL, 0); - return fcntl(fd, F_SETFL, flags ^ O_NONBLOCK); + return fcntl(fd, F_SETFL, flags & ~O_NONBLOCK); #endif } diff --git a/src/threadengines/threadengine_win32.cpp b/src/threadengines/threadengine_win32.cpp index 4bac4f5dc..5c62b5081 100644 --- a/src/threadengines/threadengine_win32.cpp +++ b/src/threadengines/threadengine_win32.cpp @@ -59,7 +59,7 @@ class ThreadSignalSocket : public BufferedSocket : BufferedSocket(SI, newfd, ip), parent(t) { } - + virtual bool OnDataReady() { char data = 0; @@ -72,52 +72,30 @@ class ThreadSignalSocket : public BufferedSocket } }; -class ThreadSignalListener : public ListenSocketBase -{ - SocketThread* parent; - sockaddr_in sock_us; - public: - ThreadSignalListener(SocketThread* t, InspIRCd* Instance, int port, const std::string &addr) : ListenSocketBase(Instance, port, addr), parent(t) - { - socklen_t uslen = sizeof(sock_us); - if (getsockname(this->fd,(sockaddr*)&sock_us,&uslen)) - { - throw ModuleException("Could not getsockname() to find out port number for ITC port"); - } - } - - virtual void OnAcceptReady(int nfd) - { - new ThreadSignalSocket(parent, ServerInstance, nfd, ""); - ServerInstance->SE->DelFd(this); - } -/* Using getsockname and ntohs, we can determine which port number we were allocated */ - int GetPort() - { - return ntohs(sock_us.sin_port); - } -}; - SocketThread::SocketThread(InspIRCd* SI) { - ThreadSignalListener* listener = new ThreadSignalListener(this, SI, 0, "127.0.0.1"); - if (listener->GetFd() == -1) + int listenFD = socket(AF_INET, SOCK_STREAM, 0); + if (listenFD == -1) throw CoreException("Could not create ITC pipe"); int connFD = socket(AF_INET, SOCK_STREAM, 0); if (connFD == -1) throw CoreException("Could not create ITC pipe"); - + + if (!SI->BindSocket(listenFD, 0, "127.0.0.1", true)) + throw CoreException("Could not create ITC pipe"); + SI->SE->NonBlocking(connFD); + struct sockaddr_in addr; - inet_aton("127.0.0.1", &addr.sin_addr); - addr.sin_family = AF_INET; - addr.sin_port = htons(listener->GetPort()); + socklen_t sz = sizeof(addr); + getsockname(listenFD, reinterpret_cast(&addr), &sz); + connect(connFD, reinterpret_cast(&addr), sz); + int nfd = accept(listenFD); + if (nfd < 0) + throw CoreException("Could not create ITC pipe"); + new ThreadSignalSocket(parent, ServerInstance, nfd, "127.0.0.1"); + closesocket(listenFD); - if (connect(connFD, reinterpret_cast(&addr), sizeof(addr)) == -1) - { - SI->SE->DelFd(listener); - closesocket(connFD); - throw CoreException("Could not connet to ITC pipe"); - } + SI->SE->Blocking(connFD); this->signal.connFD = connFD; } -- cgit v1.2.3