From 7d4edd5ac3987ff1161a5152e3aa19c8a0a8260a Mon Sep 17 00:00:00 2001 From: burlex Date: Thu, 14 Jun 2007 22:00:17 +0000 Subject: - Made the recvfrom wrapper a bit neater. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7314 e03df62e-2008-0410-955e-edbf42e46eb7 --- include/socket.h | 2 ++ src/dns.cpp | 10 +--------- src/socketengine_iocp.cpp | 7 +++++++ win/inspircd_win32wrapper.h | 2 ++ 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/include/socket.h b/include/socket.h index 1304ecb57..db0aa7f92 100644 --- a/include/socket.h +++ b/include/socket.h @@ -41,7 +41,9 @@ #ifdef CONFIG_USE_IOCP #define _accept(s, addr, addrlen) __accept_socket(s, addr, addrlen, m_acceptEvent) #define _getsockname(fd, sockptr, socklen) __getsockname(fd, sockptr, socklen, m_acceptEvent) +#define _recvfrom(s, buf, len, flags, from, fromlen) __recvfrom(s, buf, len, flags, from, fromlen, ((IOCPEngine*)ServerInstance->SE)->udp_ov) #else +#define _recvfrom recvfrom #define _accept accept #define _getsockname getsockname #endif diff --git a/src/dns.cpp b/src/dns.cpp index 2d8fdeb65..c3e909700 100644 --- a/src/dns.cpp +++ b/src/dns.cpp @@ -624,15 +624,7 @@ 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 + int length = _recvfrom(this->GetFd(),(char*)buffer,sizeof(DNSHeader),0,from,&x); /* Did we get the whole header? */ if (length < 12) diff --git a/src/socketengine_iocp.cpp b/src/socketengine_iocp.cpp index 8144c8be2..ff29716b7 100644 --- a/src/socketengine_iocp.cpp +++ b/src/socketengine_iocp.cpp @@ -349,6 +349,13 @@ int __getsockname(SOCKET s, sockaddr * name, int * namelen, void * acceptevent) return 0; } +int __recvfrom(SOCKET s, char * buf, int len, int flags, struct sockaddr * from, int * fromlen, udp_overlap * ov) +{ + memcpy(buf, ov->udp_buffer, ov->udp_len); + memcpy(from, ov->udp_sockaddr, *fromlen); + return ov->udp_len; +} + EventHandler * IOCPEngine::GetRef(int fd) { map::iterator itr = m_binding.find(fd); diff --git a/win/inspircd_win32wrapper.h b/win/inspircd_win32wrapper.h index c4be4f9e5..87baf9781 100644 --- a/win/inspircd_win32wrapper.h +++ b/win/inspircd_win32wrapper.h @@ -118,8 +118,10 @@ extern char optarg[514]; int getopt_long_only (int ___argc, char *const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind); /* Accept Handlers */ +struct udp_overlap; CoreExport int __accept_socket(SOCKET s, sockaddr * addr, int * addrlen, void * acceptevent); CoreExport int __getsockname(SOCKET s, sockaddr * name, int * namelen, void * acceptevent); +CoreExport int __recvfrom(SOCKET s, char * buf, int len, int flags, struct sockaddr * from, int * fromlen, udp_overlap * ov); /* Module Loading */ #define dlopen(path, state) (void*)LoadLibrary(path) -- cgit v1.2.3