diff options
author | burlex <burlex@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-06-14 21:33:07 +0000 |
---|---|---|
committer | burlex <burlex@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-06-14 21:33:07 +0000 |
commit | 2b293ebe7586687df2df9c87eb1b05697b4d318a (patch) | |
tree | 075b8dea7e2e3dcce95606103edbe3f57553871f /src | |
parent | bbf6f3c5d25b1569e20f6cb59898f33137ba2226 (diff) |
- Fixed UDP Overlapped I/O under windows. (not the best way this could be done by far, but probably the best that is possible with our EventHandler setup). *dns will now work under win32* :)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7313 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r-- | src/dns.cpp | 10 | ||||
-rw-r--r-- | src/socketengine_iocp.cpp | 43 |
2 files changed, 43 insertions, 10 deletions
diff --git a/src/dns.cpp b/src/dns.cpp index 99b156bf1..2d8fdeb65 100644 --- a/src/dns.cpp +++ b/src/dns.cpp @@ -29,6 +29,7 @@ looks like this, walks like this or tastes like this. #include <arpa/inet.h> #else #include "inspircd_win32wrapper.h" +#include "inspircd_se_config.h" #endif #include "dns.h" @@ -623,8 +624,15 @@ DNSResult DNS::GetResult() #endif const char* ipaddr_from; unsigned short int port_from = 0; - +#ifdef USING_IOCP + /** Dirty hack for IOCP UDP sockets **/ + udp_overlap * ov = ((IOCPEngine*)ServerInstance->SE)->udp_ov; + memcpy(buffer, ov->udp_buffer, ov->udp_len); + memcpy(from, ov->udp_sockaddr, ov->udp_sockaddr_len); + int length = ov->udp_len; +#else int length = recvfrom(this->GetFd(),(char*)buffer,sizeof(DNSHeader),0,from,&x); +#endif /* Did we get the whole header? */ if (length < 12) diff --git a/src/socketengine_iocp.cpp b/src/socketengine_iocp.cpp index 82462f8b9..8144c8be2 100644 --- a/src/socketengine_iocp.cpp +++ b/src/socketengine_iocp.cpp @@ -98,7 +98,12 @@ bool IOCPEngine::DelFd(EventHandler* eh, bool force /* = false */) /* Free the buffer, and delete the event. */ if(eh->m_readEvent != 0) + { + if(((Overlapped*)eh->m_readEvent)->m_params != 0) + delete ((udp_overlap*)((Overlapped*)eh->m_readEvent)->m_params); + delete ((Overlapped*)eh->m_readEvent); + } if(eh->m_writeEvent != 0) delete ((Overlapped*)eh->m_writeEvent); @@ -166,10 +171,15 @@ void IOCPEngine::PostReadEvent(EventHandler * eh) { case SOCK_DGRAM: /* UDP Socket */ { - if(WSARecvFrom(eh->GetFd(), &buf, 1, &r_length, &flags, 0, 0, &ov->m_overlap, 0)) + udp_overlap * uv = new udp_overlap; + uv->udp_sockaddr_len = sizeof(sockaddr); + buf.buf = (char*)uv->udp_buffer; + buf.len = sizeof(uv->udp_buffer); + ov->m_params = (unsigned long)uv; + if(WSARecvFrom(eh->GetFd(), &buf, 1, &uv->udp_len, &flags, uv->udp_sockaddr, (LPINT)&uv->udp_sockaddr_len, &ov->m_overlap, 0)) { int err = WSAGetLastError(); - if(WSAGetLastError() != WSA_IO_PENDING) + if(err != WSA_IO_PENDING) { delete ov; PostCompletionEvent(eh, SOCKET_IO_EVENT_ERROR, 0); @@ -230,17 +240,32 @@ int IOCPEngine::DispatchEvents() case SOCKET_IO_EVENT_READ_READY: { - ret = ioctlsocket(eh->GetFd(), FIONREAD, &bytes_recv); - eh->m_readEvent = 0; - if(ret != 0 || bytes_recv == 0) + if(ov->m_params) { - /* end of file */ - PostCompletionEvent(eh, SOCKET_IO_EVENT_ERROR, EIO); /* Old macdonald had an error, EIEIO. */ + // if we had params, it means we are a udp socket with a udp_overlap pointer in this long. + udp_overlap * uv = (udp_overlap*)ov->m_params; + uv->udp_len = len; + this->udp_ov = uv; + eh->m_readEvent = 0; + eh->HandleEvent(EVENT_READ, 0); + this->udp_ov = 0; + delete uv; + PostReadEvent(eh); } else { - eh->HandleEvent(EVENT_READ, 0); - PostReadEvent(eh); + ret = ioctlsocket(eh->GetFd(), FIONREAD, &bytes_recv); + eh->m_readEvent = 0; + if(ret != 0 || bytes_recv == 0) + { + /* end of file */ + PostCompletionEvent(eh, SOCKET_IO_EVENT_ERROR, EIO); /* Old macdonald had an error, EIEIO. */ + } + else + { + eh->HandleEvent(EVENT_READ, 0); + PostReadEvent(eh); + } } } break; |