diff options
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]; -} |