Browse Source

WITH_WEPOLL on windows (#389)

ithewei 2 years ago
parent
commit
7f6016d8c6
6 changed files with 21 additions and 7 deletions
  1. 6 0
      CMakeLists.txt
  2. 0 4
      base/hsocket.h
  3. 6 1
      event/epoll.c
  4. 5 2
      event/iowatcher.h
  5. 3 0
      hconfig.h
  6. 1 0
      hconfig.h.in

+ 6 - 0
CMakeLists.txt

@@ -30,6 +30,7 @@ option(WITH_MBEDTLS "with mbedtls library" OFF)
 option(WITH_KCP "with kcp" OFF)
 
 if(WIN32)
+    option(WITH_WEPOLL "with wepoll -> use iocp" ON)
     option(ENABLE_WINDUMP "Windows MiniDumpWriteDump" OFF)
     option(BUILD_FOR_MT "build for /MT" OFF)
     if(BUILD_FOR_MT)
@@ -174,6 +175,11 @@ endif()
 # see Makefile
 set(ALL_SRCDIRS . base ssl event event/kcp util cpputil evpp protocol http http/client http/server mqtt)
 set(CORE_SRCDIRS . base ssl event)
+if(WIN32)
+    if(WITH_WEPOLL)
+        set(CORE_SRCDIRS ${CORE_SRCDIRS} event/wepoll)
+    endif()
+endif()
 if(WITH_KCP)
     set(CORE_SRCDIRS ${CORE_SRCDIRS} event/kcp)
 endif()

+ 0 - 4
base/hsocket.h

@@ -42,10 +42,6 @@ HV_INLINE int nonblocking(int sockfd) {
     return ioctlsocket(sockfd, FIONBIO, &nb);
 }
 
-#ifndef poll
-#define poll        WSAPoll
-#endif
-
 #undef  EAGAIN
 #define EAGAIN      WSAEWOULDBLOCK
 

+ 6 - 1
event/epoll.c

@@ -5,7 +5,12 @@
 #include "hdef.h"
 #include "hevent.h"
 
+#ifdef OS_WIN
+#include "wepoll/wepoll.h"
+#else
 #include <sys/epoll.h>
+#define epoll_close(epfd) close(epfd)
+#endif
 
 #include "array.h"
 #define EVENTS_INIT_SIZE    64
@@ -29,7 +34,7 @@ int iowatcher_init(hloop_t* loop) {
 int iowatcher_cleanup(hloop_t* loop) {
     if (loop->iowatcher == NULL) return 0;
     epoll_ctx_t* epoll_ctx = (epoll_ctx_t*)loop->iowatcher;
-    close(epoll_ctx->epfd);
+    epoll_close(epoll_ctx->epfd);
     events_cleanup(&epoll_ctx->events);
     HV_FREE(loop->iowatcher);
     return 0;

+ 5 - 2
event/iowatcher.h

@@ -12,8 +12,11 @@
     !defined(EVENT_PORT) &&     \
     !defined(EVENT_NOEVENT)
 #ifdef OS_WIN
-// #define EVENT_IOCP // IOCP improving
-#define EVENT_POLL
+  #if WITH_WEPOLL
+    #define EVENT_EPOLL // wepoll -> iocp
+  #else
+    #define EVENT_POLL  // WSAPoll
+  #endif
 #elif defined(OS_LINUX)
 #define EVENT_EPOLL
 #elif defined(OS_MAC)

+ 3 - 0
hconfig.h

@@ -92,8 +92,11 @@
 /* #undef WITH_OPENSSL */
 /* #undef WITH_GNUTLS */
 /* #undef WITH_MBEDTLS */
+
 /* #undef ENABLE_UDS */
 /* #undef USE_MULTIMAP */
+
+#define WITH_WPOLL     1
 /* #undef WITH_KCP */
 
 #endif // HV_CONFIG_H_

+ 1 - 0
hconfig.h.in

@@ -96,6 +96,7 @@
 #cmakedefine ENABLE_UDS     1
 #cmakedefine USE_MULTIMAP   1
 
+#cmakedefine WITH_WPOLL     1
 #cmakedefine WITH_KCP       1
 
 #endif // HV_CONFIG_H_