From 1f9dd2fbf44255d8406b853516fe87d28c54ea5f Mon Sep 17 00:00:00 2001 From: Linus Yang Date: Thu, 22 Mar 2018 18:54:42 +0800 Subject: [PATCH] MinGW: fix socket closing in wrong place --- src/local.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/local.c b/src/local.c index 684230e1..2dea3a3d 100644 --- a/src/local.c +++ b/src/local.c @@ -110,6 +110,7 @@ static struct ev_signal sigterm_watcher; static struct ev_signal sigchld_watcher; static struct ev_signal sigusr1_watcher; #else +#ifndef LIB_ONLY static struct plugin_watcher_t { ev_io io; SOCKET fd; @@ -117,6 +118,7 @@ static struct plugin_watcher_t { int valid; } plugin_watcher; #endif +#endif #ifdef HAVE_SETRLIMIT #ifndef LIB_ONLY @@ -1323,7 +1325,9 @@ signal_cb(EV_P_ ev_signal *w, int revents) ev_signal_stop(EV_DEFAULT, &sigchld_watcher); ev_signal_stop(EV_DEFAULT, &sigusr1_watcher); #else +#ifndef LIB_ONLY ev_io_stop(EV_DEFAULT, &plugin_watcher.io); +#endif #endif keep_resolving = 0; ev_unloop(EV_A_ EVUNLOOP_ALL); @@ -1890,6 +1894,10 @@ main(int argc, char **argv) } #ifdef __MINGW32__ + if (plugin_watcher.valid) { + closesocket(plugin_watcher.fd); + } + winsock_cleanup(); #endif @@ -2039,10 +2047,6 @@ _start_ss_local_server(profile_t profile, ss_local_callback callback, void *udat } #ifdef __MINGW32__ - if (plugin_watcher.valid) { - closesocket(plugin_watcher.fd); - } - winsock_cleanup(); #endif