X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fthreadengines%2Fthreadengine_win32.cpp;h=b2a4dcacac0b50eab18e43e94815a31037f36609;hb=9133c3302428eb81f6d970502f811e8168079d5a;hp=eb710bbdeaec99fe2c9cbc64c31b13654b2c0fbb;hpb=fe97bfba2c13020ff4f5b5a777542fe7a783d510;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/threadengines/threadengine_win32.cpp b/src/threadengines/threadengine_win32.cpp index eb710bbde..b2a4dcaca 100644 --- a/src/threadengines/threadengine_win32.cpp +++ b/src/threadengines/threadengine_win32.cpp @@ -2,7 +2,7 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * InspIRCd: (C) 2002-2009 InspIRCd Development Team + * InspIRCd: (C) 2002-2010 InspIRCd Development Team * See: http://wiki.inspircd.org/Credits * * This program is free but copyrighted software; see @@ -14,7 +14,7 @@ #include "inspircd.h" #include "threadengines/threadengine_win32.h" -ThreadEngine::ThreadEngine(InspIRCd* Instance) +ThreadEngine::ThreadEngine() { } @@ -40,7 +40,7 @@ ThreadEngine::~ThreadEngine() DWORD WINAPI ThreadEngine::Entry(void* parameter) { - Thread* pt = reinterpret_cast(parameter); + Thread* pt = static_cast(parameter); pt->Run(); return 0; } @@ -55,81 +55,47 @@ class ThreadSignalSocket : public BufferedSocket { SocketThread* parent; public: - ThreadSignalSocket(SocketThread* t, InspIRCd* SI, int newfd, char* ip) - : BufferedSocket(SI, newfd, ip), parent(t) + ThreadSignalSocket(SocketThread* t, int newfd) + : BufferedSocket(newfd), parent(t) { } - - virtual bool OnDataReady() - { - char data = 0; - if (ServerInstance->SE->Recv(this, &data, 1, 0) > 0) - { - parent->OnNotify(); - return true; - } - return false; - } -}; -class ThreadSignalListener : public ListenSocketBase -{ - SocketThread* parent; - irc::sockets::insp_sockaddr sock_us; - public: - ThreadSignalListener(SocketThread* t, InspIRCd* Instance, int port, const std::string &addr) : ListenSocketBase(Instance, port, addr), parent(t) + void OnDataReady() { - 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"); - } + recvq.clear(); + parent->OnNotify(); } - virtual void OnAcceptReady(const std::string &ipconnectedto, int nfd, const std::string &incomingip) - { - new ThreadSignalSocket(parent, ServerInstance, nfd, const_cast(ipconnectedto.c_str())); - ServerInstance->SE->DelFd(this); - // XXX unsafe casts suck - } -/* Using getsockname and ntohs, we can determine which port number we were allocated */ - int GetPort() + void OnError(BufferedSocketError) { -#ifdef IPV6 - return ntohs(sock_us.sin6_port); -#else - return ntohs(sock_us.sin_port); -#endif + ServerInstance->GlobalCulls.AddItem(this); } }; -SocketThread::SocketThread(InspIRCd* SI) +SocketThread::SocketThread() { - 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"); - - irc::sockets::insp_sockaddr addr; - -#ifdef IPV6 - irc::sockets::insp_aton("::1", &addr.sin6_addr); - addr.sin6_family = AF_INET6; - addr.sin6_port = htons(listener->GetPort()); -#else - irc::sockets::insp_aton("127.0.0.1", &addr.sin_addr); - addr.sin_family = AF_INET; - addr.sin_port = htons(listener->GetPort()); -#endif - - if (connect(connFD, reinterpret_cast(&addr), sizeof(addr)) == -1) - { - SI->SE->DelFd(listener); - closesocket(connFD); - throw CoreException("Could not connet to ITC pipe"); - } + + if (!ServerInstance->BindSocket(listenFD, 0, "127.0.0.1", true)) + throw CoreException("Could not create ITC pipe"); + ServerInstance->SE->NonBlocking(connFD); + + struct sockaddr_in addr; + socklen_t sz = sizeof(addr); + getsockname(listenFD, reinterpret_cast(&addr), &sz); + connect(connFD, reinterpret_cast(&addr), sz); + int nfd = accept(listenFD, reinterpret_cast(&addr), (int*)sz); + if (nfd < 0) + throw CoreException("Could not create ITC pipe"); + new ThreadSignalSocket(this, nfd); + closesocket(listenFD); + + ServerInstance->SE->Blocking(connFD); this->signal.connFD = connFD; }