diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-08-23 22:06:04 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-08-23 22:06:04 +0000 |
commit | d0d36795e807cf72295c6e73813e0c2daa0a71e7 (patch) | |
tree | 09ae4d94ed7b6f3038d2579037fd2c7ee93a6657 /src/socketengine_iocp.cpp | |
parent | 61816ef0dd848225e9ec1c21c3c7a3bc03a34da9 (diff) |
Craquity craq De-craq!
This is probably broken on windows, do not attempt to use there yet unless you like broken stuff. Cant say for sure as i havent even tried to build yet and most likely wont tonight.
--- Abstract most of the berkely socket API out into SocketEngine derived classes. SocketEngine base class implements standard berkely sockets that 'real mens systems' like linux
and freebsd have. For socketengine_iocp we implement the windows specific nonesense like the special things needed for udp and accept (ick).
All this to eliminate a bunch of ifdefs.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7810 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/socketengine_iocp.cpp')
-rw-r--r-- | src/socketengine_iocp.cpp | 93 |
1 files changed, 60 insertions, 33 deletions
diff --git a/src/socketengine_iocp.cpp b/src/socketengine_iocp.cpp index eb881f280..f1f4f0289 100644 --- a/src/socketengine_iocp.cpp +++ b/src/socketengine_iocp.cpp @@ -410,11 +410,51 @@ std::string IOCPEngine::GetName() return "iocp"; } -int __accept_socket(SOCKET s, sockaddr * addr, int * addrlen, void * acceptevent) +EventHandler * IOCPEngine::GetRef(int fd) { - Overlapped* ovl = (Overlapped*)acceptevent; - accept_overlap* ov = (accept_overlap*)ovl->m_params; + map<int, EventHandler*>::iterator itr = m_binding.find(fd); + return (itr == m_binding.end()) ? 0 : itr->second; +} +bool IOCPEngine::HasFd(int fd) +{ + return (GetRef(fd) != 0); +} + +bool IOCPEngine::BoundsCheckFd(EventHandler* eh) +{ + int * internal_fd; + if (!eh || eh->GetFd() < 0) + return false; + + if(!eh->GetExt("internal_fd", internal_fd)) + return false; + + if(*internal_fd > MAX_DESCRIPTORS) + return false; + + return true; +} + +EventHandler * IOCPEngine::GetIntRef(int fd) +{ + if(fd < 0 || fd > MAX_DESCRIPTORS) + return 0; + return ref[fd]; +} + +int IOCPEngine::Accept(EventHandler* fd, sockaddr *addr, socklen_t *addrlen) +{ + SOCKET s = fd->GetFd(); + + Overlapped* acceptevent = NULL; + if (!fd->GetExt("windows_acceptevent", acceptevent)) + /* Shit, no accept event on this socket! :( */ + return -1; + + Overlapped* ovl = acceptevent; + 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]; @@ -424,9 +464,13 @@ int __accept_socket(SOCKET s, sockaddr * addr, int * addrlen, void * acceptevent return ov->socket; } -int __getsockname(SOCKET s, sockaddr * name, int * namelen, void * acceptevent) +int IOCPEngine::GetSockName(EventHandler* fd, sockaddr *name, socklen_t* name) { - Overlapped* ovl = (Overlapped*)acceptevent; + Overlapped* ovl = NULL; + + if (!fd->GetExt("windows_acceptevent", acceptevent)) + return -1; + accept_overlap* ov = (accept_overlap*)ovl->m_params; sockaddr_in* server_address = (sockaddr_in*)&ov->buf[10]; @@ -438,43 +482,26 @@ 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) +int IOCPEngine::RecvFrom(EventHandler* fd, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen) { - memcpy(buf, ov->udp_buffer, ov->udp_len); + udp_overlap * ov = NULL; + if (!fd->GetExt("windows_readevent", ov)) + return -1; + memcpy(buf, ov->udp_buffer, ov->udp_len); memcpy(from, ov->udp_sockaddr, *fromlen); return ov->udp_len; } -EventHandler * IOCPEngine::GetRef(int fd) -{ - map<int, EventHandler*>::iterator itr = m_binding.find(fd); - return (itr == m_binding.end()) ? 0 : itr->second; -} - -bool IOCPEngine::HasFd(int fd) +int IOCPEngine::Blocking(int fd) { - return (GetRef(fd) != 0); + unsigned long opt = 0; + ioctlsocket(s, FIONBIO, &opt); } -bool IOCPEngine::BoundsCheckFd(EventHandler* eh) +int IOCPEngine::NonBlocking(int fd) { - int * internal_fd; - if (!eh || eh->GetFd() < 0) - return false; - - if(!eh->GetExt("internal_fd", internal_fd)) - return false; - - if(*internal_fd > MAX_DESCRIPTORS) - return false; - - return true; + unsigned long opt = 1; + ioctlsocket(s, FIONBIO, &opt); } -EventHandler * IOCPEngine::GetIntRef(int fd) -{ - if(fd < 0 || fd > MAX_DESCRIPTORS) - return 0; - return ref[fd]; -} |