From 8df0a7c83dfd82de8d4b1eca5a9a85b5df966da0 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Thu, 16 Nov 2017 18:03:30 +0800 Subject: [PATCH] Fix the windows socket issue with MinGW --- src/local.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/local.c b/src/local.c index 50076f5..2591fcd 100644 --- a/src/local.c +++ b/src/local.c @@ -51,6 +51,9 @@ #ifdef __MINGW32__ #include "win32.h" +#define __ev_io_init(a, b, c, d) ev_io_init(a, b, _open_osfhandle(c, 0), d) +#else +#define __ev_io_init(a, b, c, d) ev_io_init(a, b, c, d) #endif #include "netutils.h" @@ -669,8 +672,8 @@ new_remote(int fd, int timeout) remote->recv_ctx->remote = remote; remote->send_ctx->remote = remote; - ev_io_init(&remote->recv_ctx->io, remote_recv_cb, fd, EV_READ); - ev_io_init(&remote->send_ctx->io, remote_send_cb, fd, EV_WRITE); + __ev_io_init(&remote->recv_ctx->io, remote_recv_cb, fd, EV_READ); + __ev_io_init(&remote->send_ctx->io, remote_send_cb, fd, EV_WRITE); ev_timer_init(&remote->send_ctx->watcher, remote_timeout_cb, min(MAX_CONNECT_TIMEOUT, timeout), 0); ev_timer_init(&remote->recv_ctx->watcher, remote_timeout_cb, @@ -733,8 +736,8 @@ new_server(int fd) memset(server->obfs, 0, sizeof(obfs_t)); } - ev_io_init(&server->recv_ctx->io, server_recv_cb, fd, EV_READ); - ev_io_init(&server->send_ctx->io, server_send_cb, fd, EV_WRITE); + __ev_io_init(&server->recv_ctx->io, server_recv_cb, fd, EV_READ); + __ev_io_init(&server->send_ctx->io, server_send_cb, fd, EV_WRITE); cork_dllist_add(&connections, &server->entries); @@ -1214,11 +1217,11 @@ main(int argc, char **argv) ev_signal_start(EV_DEFAULT, &sigterm_watcher); #endif - ev_timer parent_watcher; #ifndef __MINGW32__ + ev_timer parent_watcher; ev_timer_init(&parent_watcher, parent_watcher_cb, 0, UPDATE_INTERVAL); -#endif ev_timer_start(EV_DEFAULT, &parent_watcher); +#endif struct ev_loop *loop = EV_DEFAULT; @@ -1239,7 +1242,7 @@ main(int argc, char **argv) listen_ctx.fd = listenfd; - ev_io_init(&listen_ctx.io, accept_cb, listenfd, EV_READ); + __ev_io_init(&listen_ctx.io, accept_cb, listenfd, EV_READ); ev_io_start(loop, &listen_ctx.io); #ifdef HAVE_LAUNCHD