From 42d714eded0d33a28bd46a3a6edd51263391589a Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Fri, 8 Dec 2017 19:30:35 +0100 Subject: [PATCH 01/20] gitignore: ignore executable and library outputs --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index c85379c..f793551 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,9 @@ *_REMOTE_* *_LOCAL_* +*.a +*.dll +*.exe *.opensdf *.orig *.sdf From d26c10f85250e2940905156e48ef34092f3f3c90 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Fri, 8 Dec 2017 18:58:54 +0100 Subject: [PATCH 02/20] nt: remove unnecessary '#ifdef _NTDEF_' condition --- src/nt.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/nt.h b/src/nt.h index d50656c..8659100 100644 --- a/src/nt.h +++ b/src/nt.h @@ -6,10 +6,8 @@ WEPOLL_INTERNAL int nt_global_init(void); -#ifndef _NTDEF_ typedef LONG NTSTATUS; typedef NTSTATUS* PNTSTATUS; -#endif #ifndef NT_SUCCESS #define NT_SUCCESS(status) (((NTSTATUS)(status)) >= 0) From d84e928508b6922420313cc7cfeac7126608c971 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Fri, 8 Dec 2017 19:22:45 +0100 Subject: [PATCH 03/20] win: add missing comment after final #endif --- src/win.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/win.h b/src/win.h index 68dc900..9abd59d 100644 --- a/src/win.h +++ b/src/win.h @@ -13,4 +13,4 @@ #pragma warning(pop) -#endif +#endif /* WEPOLL_WIN_H_ */ From 05c384b18102eb8786b2974eb871aafdc9f733df Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Fri, 8 Dec 2017 19:33:03 +0100 Subject: [PATCH 04/20] src: rename WEPOLL_INTERNAL_EXTERN to WEPOLL_INTERNAL_VAR --- src/combined/internal.h | 2 +- src/nt.h | 2 +- src/regular/internal.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/combined/internal.h b/src/combined/internal.h index 7061e4c..7d36eff 100644 --- a/src/combined/internal.h +++ b/src/combined/internal.h @@ -2,6 +2,6 @@ #define WEPOLL_INTERNAL_H_ #define WEPOLL_INTERNAL static -#define WEPOLL_INTERNAL_EXTERN static +#define WEPOLL_INTERNAL_VAR static #endif /* WEPOLL_INTERNAL_H_ */ diff --git a/src/nt.h b/src/nt.h index 8659100..4dd130a 100644 --- a/src/nt.h +++ b/src/nt.h @@ -136,7 +136,7 @@ typedef struct _OBJECT_ATTRIBUTES { (HANDLE handle, PVOID key, BOOLEAN alertable, PLARGE_INTEGER mstimeout)) #define X(return_type, attributes, name, parameters) \ - WEPOLL_INTERNAL_EXTERN return_type(attributes* name) parameters; + WEPOLL_INTERNAL_VAR return_type(attributes* name) parameters; NTDLL_IMPORT_LIST(X) #undef X diff --git a/src/regular/internal.h b/src/regular/internal.h index 6a108ac..95d51b6 100644 --- a/src/regular/internal.h +++ b/src/regular/internal.h @@ -2,6 +2,6 @@ #define WEPOLL_INTERNAL_H_ #define WEPOLL_INTERNAL -#define WEPOLL_INTERNAL_EXTERN extern +#define WEPOLL_INTERNAL_VAR extern #endif /* WEPOLL_INTERNAL_H_ */ From 1ad34ec3f3dd7a6d48eec3b886e5a4da5c8df974 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Fri, 8 Dec 2017 19:20:42 +0100 Subject: [PATCH 05/20] util: rename 'unused' macro to 'unused_var' --- src/init.c | 6 +++--- src/port.c | 6 +++--- src/reflock.c | 6 +++--- src/util.h | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/init.c b/src/init.c index b6dadf0..5f75421 100644 --- a/src/init.c +++ b/src/init.c @@ -25,9 +25,9 @@ static int _winsock_global_init(void) { static BOOL CALLBACK _init_once_callback(INIT_ONCE* once, void* parameter, void** context) { - unused(once); - unused(parameter); - unused(context); + unused_var(once); + unused_var(parameter); + unused_var(context); if (_winsock_global_init() < 0 || nt_global_init() < 0 || reflock_global_init() < 0 || api_global_init() < 0) diff --git a/src/port.c b/src/port.c index 4505321..47a569c 100644 --- a/src/port.c +++ b/src/port.c @@ -385,7 +385,7 @@ poll_group_t* ep_port_acquire_poll_group( void ep_port_release_poll_group(ep_port_t* port_info, poll_group_t* poll_group) { - unused(port_info); + unused_var(port_info); poll_group_release(poll_group); } @@ -397,7 +397,7 @@ void ep_port_request_socket_update(ep_port_t* port_info, } void ep_port_cancel_socket_update(ep_port_t* port_info, ep_sock_t* sock_info) { - unused(port_info); + unused_var(port_info); if (!queue_enqueued(&sock_info->queue_node)) return; queue_remove(&sock_info->queue_node); @@ -411,7 +411,7 @@ void ep_port_add_deleted_socket(ep_port_t* port_info, ep_sock_t* sock_info) { void ep_port_remove_deleted_socket(ep_port_t* port_info, ep_sock_t* sock_info) { - unused(port_info); + unused_var(port_info); if (!queue_enqueued(&sock_info->queue_node)) return; queue_remove(&sock_info->queue_node); diff --git a/src/reflock.c b/src/reflock.c index 9463ee1..a8a51f9 100644 --- a/src/reflock.c +++ b/src/reflock.c @@ -64,7 +64,7 @@ static inline uint32_t _sync_fetch_and_set(volatile uint32_t* target, void reflock_ref(reflock_t* reflock) { uint32_t state = _sync_add_and_fetch(&reflock->state, _REF); - unused(state); + unused_var(state); assert((state & _DESTROY_MASK) == 0); /* Overflow or destroyed. */ } @@ -73,8 +73,8 @@ void reflock_unref(reflock_t* reflock) { uint32_t ref_count = state & _REF_MASK; uint32_t destroy = state & _DESTROY_MASK; - unused(ref_count); - unused(destroy); + unused_var(ref_count); + unused_var(destroy); if (state == _DESTROY) _signal_event(reflock); diff --git a/src/util.h b/src/util.h index eb42632..ce9af95 100644 --- a/src/util.h +++ b/src/util.h @@ -18,7 +18,7 @@ typedef intptr_t ssize_t; #define safe_container_of(ptr, type, member) \ ((type*) util_safe_container_of_helper((ptr), offsetof(type, member))) -#define unused(v) ((void) (v)) +#define unused_var(v) ((void) (v)) #if defined(_MSC_VER) && _MSC_VER < 1900 /* Polyfill `inline` for msvc 12 (Visual Studio 2013) */ From 2b57c726c858f401077fa90ef8f2bf9a14482ccc Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Fri, 8 Dec 2017 19:14:00 +0100 Subject: [PATCH 06/20] util: move 'unused_fn' macro to from rb.h to util.h --- src/rb.h | 18 +++++++----------- src/util.h | 6 ++++++ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/rb.h b/src/rb.h index 3fcbc9d..4472403 100644 --- a/src/rb.h +++ b/src/rb.h @@ -23,6 +23,11 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#ifndef WEPOLL_RB_H_ +#define WEPOLL_RB_H_ + +#include "util.h" + /* * A red-black tree is a binary search tree with the node color as an * extra attribute. It fulfills a set of conditions: @@ -35,15 +40,6 @@ * The maximum height of a red-black tree is 2lg (n+1). */ -#ifndef WEPOLL_RB_H_ -#define WEPOLL_RB_H_ - -#ifdef __clang__ -#define RB_UNUSED __attribute__((__unused__)) -#else -#define RB_UNUSED /* empty */ -#endif - /* clang-format off */ /* Macros that define a red-black tree */ @@ -123,7 +119,7 @@ struct { \ #define RB_PROTOTYPE(name, type, field, cmp) \ RB_PROTOTYPE_INTERNAL(name, type, field, cmp,) #define RB_PROTOTYPE_STATIC(name, type, field, cmp) \ - RB_PROTOTYPE_INTERNAL(name, type, field, cmp, static RB_UNUSED) + RB_PROTOTYPE_INTERNAL(name, type, field, cmp, static unused_fn) #define RB_PROTOTYPE_INTERNAL(name, type, field, cmp, attr) \ attr void name##_RB_INSERT_COLOR(struct name *, struct type *); \ attr void name##_RB_REMOVE_COLOR(struct name *, struct type *, struct type *);\ @@ -142,7 +138,7 @@ attr struct type *name##_RB_MINMAX(struct name *, int); \ #define RB_GENERATE(name, type, field, cmp) \ RB_GENERATE_INTERNAL(name, type, field, cmp,) #define RB_GENERATE_STATIC(name, type, field, cmp) \ - RB_GENERATE_INTERNAL(name, type, field, cmp, static RB_UNUSED) + RB_GENERATE_INTERNAL(name, type, field, cmp, static unused_fn) #define RB_GENERATE_INTERNAL(name, type, field, cmp, attr) \ attr void \ name##_RB_INSERT_COLOR(struct name *head, struct type *elm) \ diff --git a/src/util.h b/src/util.h index ce9af95..2db67c8 100644 --- a/src/util.h +++ b/src/util.h @@ -20,6 +20,12 @@ typedef intptr_t ssize_t; #define unused_var(v) ((void) (v)) +#ifdef __clang__ +#define unused_fn __attribute__((__unused__)) +#else +#define unused_fn /* nothing */ +#endif + #if defined(_MSC_VER) && _MSC_VER < 1900 /* Polyfill `inline` for msvc 12 (Visual Studio 2013) */ #define inline __inline From a2eeaa5f82170c987b214f7f907c7a4edb9ecf16 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Fri, 8 Dec 2017 19:01:34 +0100 Subject: [PATCH 07/20] src: move variable declarations to top of block --- src/afd.c | 5 +++-- src/port.c | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/afd.c b/src/afd.c index 425ec1c..33abca5 100644 --- a/src/afd.c +++ b/src/afd.c @@ -107,8 +107,9 @@ static SOCKET _afd_get_base_socket(SOCKET socket) { static ssize_t _afd_get_protocol_info(SOCKET socket, WSAPROTOCOL_INFOW* protocol_info) { - ssize_t id; int opt_len; + ssize_t id; + size_t i; opt_len = sizeof *protocol_info; if (getsockopt(socket, @@ -119,7 +120,7 @@ static ssize_t _afd_get_protocol_info(SOCKET socket, return_error(-1); id = -1; - for (size_t i = 0; i < array_count(AFD_PROVIDER_GUID_LIST); i++) { + for (i = 0; i < array_count(AFD_PROVIDER_GUID_LIST); i++) { if (memcmp(&protocol_info->ProviderId, &AFD_PROVIDER_GUID_LIST[i], sizeof protocol_info->ProviderId) == 0) { diff --git a/src/port.c b/src/port.c index 47a569c..0ec36b4 100644 --- a/src/port.c +++ b/src/port.c @@ -88,6 +88,7 @@ int ep_port_close(ep_port_t* port_info) { int ep_port_delete(ep_port_t* port_info) { tree_node_t* tree_node; queue_node_t* queue_node; + size_t i; EnterCriticalSection(&port_info->lock); @@ -104,7 +105,7 @@ int ep_port_delete(ep_port_t* port_info) { ep_sock_force_delete(port_info, sock_info); } - for (size_t i = 0; i < array_count(port_info->poll_group_allocators); i++) { + for (i = 0; i < array_count(port_info->poll_group_allocators); i++) { poll_group_allocator_t* pga = port_info->poll_group_allocators[i]; if (pga != NULL) poll_group_allocator_delete(pga); @@ -148,8 +149,9 @@ static int _ep_port_feed_events(ep_port_t* port_info, OVERLAPPED_ENTRY* iocp_events, int iocp_event_count) { int epoll_event_count = 0; + int i; - for (int i = 0; i < iocp_event_count; i++) { + for (i = 0; i < iocp_event_count; i++) { OVERLAPPED* overlapped = iocp_events[i].lpOverlapped; struct epoll_event* ev = &epoll_events[epoll_event_count]; From 1ef60cb893e9cbfd93f44c82a2270c1fe2362923 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Fri, 8 Dec 2017 19:26:43 +0100 Subject: [PATCH 08/20] win: ensure definitions for Vista or later are included --- src/win.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/win.h b/src/win.h index 9abd59d..b6b1329 100644 --- a/src/win.h +++ b/src/win.h @@ -5,6 +5,14 @@ #define WIN32_LEAN_AND_MEAN #endif +#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0600 +#undef _WIN32_WINNT +#endif + +#ifndef _WIN32_WINNT +#define _WIN32_WINNT 0x0600 +#endif + #pragma warning(push, 1) #include From 1a2743cf5e478daa6b918af1a763d0e329249af8 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Fri, 8 Dec 2017 19:27:30 +0100 Subject: [PATCH 09/20] win: gcc doesn't grok #pragma warning --- src/win.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/win.h b/src/win.h index b6b1329..e7fa39b 100644 --- a/src/win.h +++ b/src/win.h @@ -13,12 +13,16 @@ #define _WIN32_WINNT 0x0600 #endif +#ifndef __GNUC__ #pragma warning(push, 1) +#endif #include #include #include +#ifndef __GNUC__ #pragma warning(pop) +#endif #endif /* WEPOLL_WIN_H_ */ From e10424bf5882d6993021a179cb68dae5159bc657 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Fri, 8 Dec 2017 19:28:43 +0100 Subject: [PATCH 10/20] win: polyfill ERROR_DEVICE_FEATURE_NOT_SUPPORTED definition for MinGW --- src/win.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/win.h b/src/win.h index e7fa39b..32d1804 100644 --- a/src/win.h +++ b/src/win.h @@ -25,4 +25,9 @@ #pragma warning(pop) #endif +#ifndef ERROR_DEVICE_FEATURE_NOT_SUPPORTED +/* Windows headers distributed with MinGW lack a definition for this. */ +#define ERROR_DEVICE_FEATURE_NOT_SUPPORTED 316L +#endif + #endif /* WEPOLL_WIN_H_ */ From ac0f54621b9153f1103c464b21b25baf630f2c7b Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Fri, 8 Dec 2017 19:29:37 +0100 Subject: [PATCH 11/20] util: enable polyfills for gcc --- src/util.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/util.h b/src/util.h index 2db67c8..3d1c674 100644 --- a/src/util.h +++ b/src/util.h @@ -20,7 +20,7 @@ typedef intptr_t ssize_t; #define unused_var(v) ((void) (v)) -#ifdef __clang__ +#if defined(__clang__) || defined(__GNUC__) #define unused_fn __attribute__((__unused__)) #else #define unused_fn /* nothing */ @@ -31,8 +31,8 @@ typedef intptr_t ssize_t; #define inline __inline #endif -#ifdef __clang__ -/* Polyfill static_assert() because clang doesn't support it. */ +#if defined(__clang__) || defined(__GNUC__) +/* Polyfill static_assert() for clang and gcc. */ #define static_assert(condition, message) typedef __attribute__( \ (unused)) int __static_assert_##__LINE__[(condition) ? 1 : -1]; #endif From d25f2bf8c4075affdc16253413c9134d387f1c42 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Fri, 8 Dec 2017 19:05:06 +0100 Subject: [PATCH 12/20] test: move variable declarations to top of block --- test/test-ctl-fuzz.c | 7 ++++--- test/test-multi-poll.c | 11 ++++++----- test/test-reflock.c | 9 ++++++--- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/test/test-ctl-fuzz.c b/test/test-ctl-fuzz.c index 89a1c24..1e68c7e 100644 --- a/test/test-ctl-fuzz.c +++ b/test/test-ctl-fuzz.c @@ -38,8 +38,9 @@ int main(void) { uint64_t total_events = 0; uint64_t start_time, last_print_time, now, total_time; SOCKET sockets[NUM_SOCKETS]; - int r; HANDLE epfd; + size_t i; + int r; r = init(); check(r == 0); @@ -47,7 +48,7 @@ int main(void) { epfd = epoll_create1(0); check(epfd != NULL); - for (size_t i = 0; i < NUM_SOCKETS; i++) + for (i = 0; i < NUM_SOCKETS; i++) sockets[i] = create_and_add_socket(epfd); start_time = GetTickCount64(); @@ -57,7 +58,7 @@ int main(void) { struct epoll_event ev_out[64]; uint64_t count; - for (size_t i = 0; i < NUM_SOCKETS; i++) { + for (i = 0; i < NUM_SOCKETS; i++) { SOCKET sock = sockets[i]; struct epoll_event ev_in; diff --git a/test/test-multi-poll.c b/test/test-multi-poll.c index 643b982..73f5287 100644 --- a/test/test-multi-poll.c +++ b/test/test-multi-poll.c @@ -90,6 +90,7 @@ int main(void) { HANDLE ports[PORT_COUNT]; test_context_t contexts[PORT_COUNT][THREADS_PER_PORT]; WSADATA wsa_data; + size_t i, j; int r; /* Initialize winsock. */ @@ -101,7 +102,7 @@ int main(void) { /* Create PORT_COUNT epoll ports which, will be polled by THREADS_PER_PORT * threads. */ - for (size_t i = 0; i < array_count(contexts); i++) { + for (i = 0; i < array_count(contexts); i++) { HANDLE port; struct epoll_event ev; @@ -117,7 +118,7 @@ int main(void) { check(r == 0); /* Start THREADS_PER_PORT threads which will all poll the port. */ - for (size_t j = 0; j < array_count(contexts[i]); j++) { + for (j = 0; j < array_count(contexts[i]); j++) { test_context_t* context = &contexts[i][j]; HANDLE thread; @@ -141,8 +142,8 @@ int main(void) { send_message(send_sock, LISTEN_PORT); /* Wait for all threads to exit and clean up after them. */ - for (size_t i = 0; i < array_count(contexts); i++) { - for (size_t j = 0; j < array_count(contexts[i]); j++) { + for (i = 0; i < array_count(contexts); i++) { + for (j = 0; j < array_count(contexts[i]); j++) { HANDLE thread = contexts[i][j].thread; DWORD wr = WaitForSingleObject(thread, INFINITE); check(wr == WAIT_OBJECT_0); @@ -151,7 +152,7 @@ int main(void) { } /* Close all epoll ports. */ - for (size_t i = 0; i < array_count(ports); i++) { + for (i = 0; i < array_count(ports); i++) { HANDLE port = ports[i]; r = epoll_close(port); check(r == 0); diff --git a/test/test-reflock.c b/test/test-reflock.c index 3526f58..e342518 100644 --- a/test/test-reflock.c +++ b/test/test-reflock.c @@ -70,10 +70,11 @@ static void destroy_reflock(test_context_t* context) { static void run_test_iteration(void) { test_context_t context; HANDLE threads[THREAD_COUNT]; + size_t i; init_context(&context); - for (size_t i = 0; i < array_count(threads); i++) { + for (i = 0; i < array_count(threads); i++) { HANDLE thread = (HANDLE) _beginthreadex(NULL, 0, test_thread, &context, 0, NULL); check(thread != INVALID_HANDLE_VALUE); @@ -84,7 +85,7 @@ static void run_test_iteration(void) { destroy_reflock(&context); - for (size_t i = 0; i < array_count(threads); i++) { + for (i = 0; i < array_count(threads); i++) { HANDLE thread = threads[i]; DWORD wr = WaitForSingleObject(thread, INFINITE); check(wr == WAIT_OBJECT_0); @@ -93,10 +94,12 @@ static void run_test_iteration(void) { } int main(void) { + int i; + if (init() < 0) return 0; - for (int i = 0; i < TEST_ITERATIONS; i++) { + for (i = 0; i < TEST_ITERATIONS; i++) { printf("Iteration %d of %d\n", i + 1, TEST_ITERATIONS); run_test_iteration(); } From e358fdc4302776af540ce0cd0252e81661447647 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Fri, 8 Dec 2017 19:24:09 +0100 Subject: [PATCH 13/20] test: use portable printf format specifier for 64-bit integer --- test/test-udp-pings.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test-udp-pings.c b/test/test-udp-pings.c index 704e375..b628ccf 100644 --- a/test/test-udp-pings.c +++ b/test/test-udp-pings.c @@ -18,7 +18,7 @@ int main(void) { u_long one = 1; struct sockaddr_in address; DWORD ticks_start, ticks_last; - long long pings = 0, pings_sent = 0; + uint64_t pings = 0, pings_sent = 0; int i; SOCKET srv; struct epoll_event ev; @@ -74,7 +74,7 @@ int main(void) { ticks = GetTickCount(); if (ticks >= ticks_last + 1000) { - printf("%lld pings (%0.0f per sec), %lld sent (%0.0f per sec)\n", + printf("%I64d pings (%0.0f per sec), %I64d sent (%0.0f per sec)\n", pings, (double) pings / (ticks - ticks_start) * 1000.0, pings_sent, From ed51c0a335a107c0d58b086c7c93b96c0ab789ec Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Fri, 8 Dec 2017 19:25:37 +0100 Subject: [PATCH 14/20] test: squelch gcc -Wparentheses warning --- test/test-ctl-fuzz.c | 2 +- test/test-udp-pings.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test-ctl-fuzz.c b/test/test-ctl-fuzz.c index 1e68c7e..9b45909 100644 --- a/test/test-ctl-fuzz.c +++ b/test/test-ctl-fuzz.c @@ -62,7 +62,7 @@ int main(void) { SOCKET sock = sockets[i]; struct epoll_event ev_in; - ev_in.events = rand() & 0xff | EPOLLONESHOT; + ev_in.events = (rand() & 0xff) | EPOLLONESHOT; ev_in.data.u64 = 42; r = epoll_ctl(epfd, EPOLL_CTL_MOD, sock, &ev_in); diff --git a/test/test-udp-pings.c b/test/test-udp-pings.c index b628ccf..90b2b7d 100644 --- a/test/test-udp-pings.c +++ b/test/test-udp-pings.c @@ -140,7 +140,7 @@ int main(void) { pings_sent++; - uint32_t rev = rand() & 0xff | EPOLLOUT | EPOLLONESHOT; + uint32_t rev = EPOLLOUT | EPOLLONESHOT; struct epoll_event e; e.data.sock = sock; e.events = rev; From d907d3f768a4953cbca0a3b3864c8d289e42a8a9 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Fri, 8 Dec 2017 19:43:56 +0100 Subject: [PATCH 15/20] doc: update compatibility section in readme --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e76bfff..c513314 100644 --- a/README.md +++ b/README.md @@ -43,9 +43,8 @@ wherever needed. ## Compatibility -* Requires Windows 7 or higher. -* Can be compiled with recent versions of MSVC and Clang. -* GCC (mingw) should work (but is untested). +* Requires Windows Vista or higher. +* Can be compiled with recent versions of MSVC, Clang, and GCC. ## API notes From 206dff3f6ae90157ec68b1773ee39ad41628fd70 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Fri, 8 Dec 2017 23:32:04 +0100 Subject: [PATCH 16/20] util: don't redefine static_assert if it's already defined --- src/util.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/util.h b/src/util.h index 3d1c674..6cfee08 100644 --- a/src/util.h +++ b/src/util.h @@ -31,10 +31,10 @@ typedef intptr_t ssize_t; #define inline __inline #endif -#if defined(__clang__) || defined(__GNUC__) -/* Polyfill static_assert() for clang and gcc. */ +#if !defined(static_assert) && !defined(_MSC_VER) +/* Polyfill `static_assert` for some versions of clang and gcc. */ #define static_assert(condition, message) typedef __attribute__( \ - (unused)) int __static_assert_##__LINE__[(condition) ? 1 : -1]; + (__unused__)) int __static_assert_##__LINE__[(condition) ? 1 : -1]; #endif WEPOLL_INTERNAL void* util_safe_container_of_helper(void* ptr, size_t offset); From 70c5a36e56e3398cce3bb95e2ea20705be0ef486 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Fri, 8 Dec 2017 21:13:10 +0100 Subject: [PATCH 17/20] build: create the dist/ directory in configure step --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ef363b..1eae4a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,7 @@ foreach(HEADER_SOURCE ${SOURCES_INCLUDE}) get_filename_component(HEADER_NAME ${HEADER_SOURCE} NAME_WE) string(TOUPPER ${HEADER_NAME} HEADER_NAME_UC) + file(MAKE_DIRECTORY dist) set(DIST_SRC_C "dist/${HEADER_NAME}.c") set(DIST_SRC_H "dist/${HEADER_NAME}.h") set(SOURCES_README "README.md") From b7ab0935319a290c341e249fbd8ce4a83acc7651 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Sat, 9 Dec 2017 04:14:03 +0100 Subject: [PATCH 18/20] util: fix typo in _SSIZE_T_DEFINED --- src/util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.h b/src/util.h index 6cfee08..e210b3a 100644 --- a/src/util.h +++ b/src/util.h @@ -6,7 +6,7 @@ #include "internal.h" #ifndef _SSIZE_T_DEFINED -#define SSIZE_T_DEFINED +#define _SSIZE_T_DEFINED typedef intptr_t ssize_t; #endif From ac432c2cce1abd181c7982a8c63d6ba826998f01 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Sat, 9 Dec 2017 23:21:28 +0100 Subject: [PATCH 19/20] gitignore: ignore some compiler outputs --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index f793551..b33bfa8 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,10 @@ *.a *.dll *.exe +*.exp +*.ilk +*.lib +*.pdb *.opensdf *.orig *.sdf From d8cf151f3044adc08b17262f257ecd174239bb61 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Sat, 9 Dec 2017 23:26:35 +0100 Subject: [PATCH 20/20] port: change some internal method names --- src/port.c | 9 +++++---- src/port.h | 10 +++++----- src/sock.c | 5 +++-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/port.c b/src/port.c index 0ec36b4..18fe6a1 100644 --- a/src/port.c +++ b/src/port.c @@ -339,15 +339,16 @@ int ep_port_ctl(ep_port_t* port_info, return result; } -int ep_port_add_socket(ep_port_t* port_info, - ep_sock_t* sock_info, - SOCKET socket) { +int ep_port_register_socket_handle(ep_port_t* port_info, + ep_sock_t* sock_info, + SOCKET socket) { if (tree_add(&port_info->sock_tree, &sock_info->tree_node, socket) < 0) return_error(-1, ERROR_ALREADY_EXISTS); return 0; } -int ep_port_del_socket(ep_port_t* port_info, ep_sock_t* sock_info) { +int ep_port_unregister_socket_handle(ep_port_t* port_info, + ep_sock_t* sock_info) { if (tree_del(&port_info->sock_tree, &sock_info->tree_node) < 0) return_error(-1, ERROR_NOT_FOUND); return 0; diff --git a/src/port.h b/src/port.h index 07151e4..eefd423 100644 --- a/src/port.h +++ b/src/port.h @@ -48,11 +48,11 @@ WEPOLL_INTERNAL poll_group_t* ep_port_acquire_poll_group( WEPOLL_INTERNAL void ep_port_release_poll_group(ep_port_t* port_info, poll_group_t* poll_group); -WEPOLL_INTERNAL int ep_port_add_socket(ep_port_t* port_info, - ep_sock_t* sock_info, - SOCKET socket); -WEPOLL_INTERNAL int ep_port_del_socket(ep_port_t* port_info, - ep_sock_t* sock_info); +WEPOLL_INTERNAL int ep_port_register_socket_handle(ep_port_t* port_info, + ep_sock_t* sock_info, + SOCKET socket); +WEPOLL_INTERNAL int ep_port_unregister_socket_handle(ep_port_t* port_info, + ep_sock_t* sock_info); WEPOLL_INTERNAL ep_sock_t* ep_port_find_socket(ep_port_t* port_info, SOCKET socket); diff --git a/src/sock.c b/src/sock.c index 7733ca4..8cdfb05 100644 --- a/src/sock.c +++ b/src/sock.c @@ -202,7 +202,8 @@ ep_sock_t* ep_sock_new(ep_port_t* port_info, SOCKET socket) { tree_node_init(&sock_private->pub.tree_node); queue_node_init(&sock_private->pub.queue_node); - if (ep_port_add_socket(port_info, &sock_private->pub, socket) < 0) + if (ep_port_register_socket_handle(port_info, &sock_private->pub, socket) < + 0) goto err2; return &sock_private->pub; @@ -225,7 +226,7 @@ static void _ep_sock_delete(ep_port_t* port_info, _ep_sock_cancel_poll(sock_private); ep_port_cancel_socket_update(port_info, sock_info); - ep_port_del_socket(port_info, sock_info); + ep_port_unregister_socket_handle(port_info, sock_info); sock_private->delete_pending = true; }