From 5d9e3d6b016e3ba4332e7f8c206f38873b7ca552 Mon Sep 17 00:00:00 2001 From: benjymous Date: Fri, 2 Oct 2020 20:14:37 +0100 Subject: [PATCH] Add a duk_trans_socket_active() function to allow application to allow for graceful shutdown --- examples/debug-trans-socket/duk_trans_socket.h | 2 ++ examples/debug-trans-socket/duk_trans_socket_unix.c | 5 +++++ examples/debug-trans-socket/duk_trans_socket_windows.c | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/examples/debug-trans-socket/duk_trans_socket.h b/examples/debug-trans-socket/duk_trans_socket.h index 4671a1dd..07637384 100644 --- a/examples/debug-trans-socket/duk_trans_socket.h +++ b/examples/debug-trans-socket/duk_trans_socket.h @@ -16,6 +16,8 @@ duk_size_t duk_trans_socket_peek_cb(void *udata); void duk_trans_socket_read_flush_cb(void *udata); void duk_trans_socket_write_flush_cb(void *udata); +duk_bool_t duk_trans_socket_active(void); + #if defined(__cplusplus) } #endif /* end 'extern "C"' wrapper */ diff --git a/examples/debug-trans-socket/duk_trans_socket_unix.c b/examples/debug-trans-socket/duk_trans_socket_unix.c index 0633eff2..555def14 100644 --- a/examples/debug-trans-socket/duk_trans_socket_unix.c +++ b/examples/debug-trans-socket/duk_trans_socket_unix.c @@ -89,6 +89,11 @@ void duk_trans_socket_finish(void) { } } +duk_bool_t duk_trans_socket_active(void) +{ + return server_sock >= 0; +} + void duk_trans_socket_waitconn(void) { struct sockaddr_in addr; socklen_t sz; diff --git a/examples/debug-trans-socket/duk_trans_socket_windows.c b/examples/debug-trans-socket/duk_trans_socket_windows.c index 59bee04d..993fbc79 100644 --- a/examples/debug-trans-socket/duk_trans_socket_windows.c +++ b/examples/debug-trans-socket/duk_trans_socket_windows.c @@ -167,6 +167,11 @@ void duk_trans_socket_finish(void) { } } +duk_bool_t duk_trans_socket_active(void) +{ + return server_sock != INVALID_SOCKET; +} + void duk_trans_socket_waitconn(void) { if (server_sock == INVALID_SOCKET) { fprintf(stderr, "%s: no server socket, skip waiting for connection\n",