]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/socketengines/socketengine_iocp.cpp
Make sure usage lines up neatly.
[user/henk/code/inspircd.git] / src / socketengines / socketengine_iocp.cpp
index 5bc1faed4d246e64a90565353d4aa6cef68be3cf..ee2e5afa18fe3f5d29a5f4e8e0f2bf9f601da323 100644 (file)
@@ -2,8 +2,8 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
- * See: http://www.inspircd.org/wiki/index.php/Credits
+ *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
+ * See: http://wiki.inspircd.org/Credits
  *
  * This program is free but copyrighted software; see
  *            the file COPYING for details.
@@ -17,6 +17,8 @@
 
 IOCPEngine::IOCPEngine(InspIRCd * Instance) : SocketEngine(Instance)
 {
+       MAX_DESCRIPTORS = 10240;
+
        /* Create completion port */
        m_completionPort = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, (ULONG_PTR)0, 0);
 
@@ -32,6 +34,8 @@ IOCPEngine::IOCPEngine(InspIRCd * Instance) : SocketEngine(Instance)
        /* Null variables out. */
        CurrentSetSize = 0;
        EngineHandle = 0;
+       MAX_DESCRIPTORS = 10240;
+       ref = new EventHandler* [10240];
        memset(ref, 0, sizeof(EventHandler*) * MAX_DESCRIPTORS);
 }
 
@@ -40,6 +44,7 @@ IOCPEngine::~IOCPEngine()
        /* Clean up winsock and close completion port */
        CloseHandle(m_completionPort);
        WSACleanup();
+       delete[] ref;
 }
 
 bool IOCPEngine::AddFd(EventHandler* eh)
@@ -161,7 +166,7 @@ bool IOCPEngine::DelFd(EventHandler* eh, bool force /* = false */)
 
        /* decrement set size */
        --CurrentSetSize;
-       
+
        /* success */
        return true;
 }
@@ -170,7 +175,7 @@ void IOCPEngine::WantWrite(EventHandler* eh)
 {
        if (!eh)
                return;
-       
+
        void* m_writeEvent = NULL;
 
        int* fake_fd = NULL;
@@ -286,7 +291,7 @@ int IOCPEngine::DispatchEvents()
 
        while (GetQueuedCompletionStatus(m_completionPort, &len, &intfd, &overlap, 1000))
        {
-               if (intfd < 0 || intfd > MAX_DESCRIPTORS)
+               if (intfd > (unsigned long)MAX_DESCRIPTORS)
                        continue;
 
                // woot, we got an event on a socket :P
@@ -346,7 +351,7 @@ int IOCPEngine::DispatchEvents()
                                }
                        }
                        break;
-               
+
                        case SOCKET_IO_EVENT_ACCEPT:
                        {
                                /* this is kinda messy.. :/ */
@@ -365,7 +370,7 @@ int IOCPEngine::DispatchEvents()
                        }
                        break;
                }
-               
+
                delete ov;
        }
 
@@ -450,7 +455,7 @@ EventHandler * IOCPEngine::GetIntRef(int fd)
 
 int IOCPEngine::Accept(EventHandler* fd, sockaddr *addr, socklen_t *addrlen)
 {
-       SOCKET s = fd->GetFd();
+       //SOCKET s = fd->GetFd();
 
        Overlapped* acceptevent = NULL;
        if (!fd->GetExt("windows_acceptevent", acceptevent))
@@ -459,8 +464,8 @@ int IOCPEngine::Accept(EventHandler* fd, sockaddr *addr, socklen_t *addrlen)
 
        Overlapped* ovl = acceptevent;
        accept_overlap* ov = (accept_overlap*)ovl->m_params;
-       
-       sockaddr_in* server_address = (sockaddr_in*)&ov->buf[10];
+
+       //sockaddr_in* server_address = (sockaddr_in*)&ov->buf[10];
        sockaddr_in* client_address = (sockaddr_in*)&ov->buf[38];
 
        memcpy(addr, client_address, sizeof(sockaddr_in));
@@ -472,14 +477,14 @@ int IOCPEngine::Accept(EventHandler* fd, sockaddr *addr, socklen_t *addrlen)
 int IOCPEngine::GetSockName(EventHandler* fd, sockaddr *name, socklen_t* namelen)
 {
        Overlapped* ovl = NULL;
-       
+
        if (!fd->GetExt("windows_acceptevent", ovl))
                return -1;
 
        accept_overlap* ov = (accept_overlap*)ovl->m_params;
 
        sockaddr_in* server_address = (sockaddr_in*)&ov->buf[10];
-       sockaddr_in* client_address = (sockaddr_in*)&ov->buf[38];
+       //sockaddr_in* client_address = (sockaddr_in*)&ov->buf[38];
 
        memcpy(name, server_address, sizeof(sockaddr_in));
        *namelen = sizeof(sockaddr_in);
@@ -489,6 +494,7 @@ int IOCPEngine::GetSockName(EventHandler* fd, sockaddr *name, socklen_t* namelen
 
 int IOCPEngine::RecvFrom(EventHandler* fd, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen)
 {
+       this->UpdateStats(len, 0);
        udp_overlap * ov = NULL;
        if (!fd->GetExt("windows_readevent", ov))
                return -1;
@@ -518,4 +524,3 @@ int IOCPEngine::Close(EventHandler* fd)
 {
        return this->Close(fd->GetFd());
 }
-