aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Timber <mieabby@gmail.com>2021-04-17 12:35:31 +1000
committerDavid Timber <mieabby@gmail.com>2021-04-17 12:37:00 +1000
commit7e065471e598c9bc0a1799ff2caa8c799d76c003 (patch)
tree11240a39d7226d55a5ddc975927ab967ce508dc4 /src
parent062454f554b77c86d9eb738d025263e1e7003ebd (diff)
bne: bug fix and improvements
* close connection for htbt vector gracefully * decrease connection timeout and increase socket operation * fix bug where both `BNE_CONN_TIMEOUT` and `BNE_CONN_OP_TIMEOUT` are used. * fix memory leak caused by htbt vector
Diffstat (limited to 'src')
-rw-r--r--src/bne.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/bne.c b/src/bne.c
index a483903..dcb1825 100644
--- a/src/bne.c
+++ b/src/bne.c
@@ -18,13 +18,12 @@
#include <mbedtls/base64.h>
-static const struct timespec BNE_CONN_OP_TIMEOUT = { 30, 0 }; // 30s
-static const struct timespec BNE_SCK_OP_TIMEOUT = { 10, 0 }; // 10s
+static const struct timespec BNE_CONN_OP_TIMEOUT = { 15, 0 }; // 15s
+static const struct timespec BNE_SCK_OP_TIMEOUT = { 30, 0 }; // 30s
static const struct timespec BNE_CLOSE_OP_TIMEOUT = { 1, 0 }; // 1s
static const struct timespec BNE_ERR_PAUSE = { 0, 500000000 }; // 500ms
static const struct timespec BNE_PROMPT_PAUSE = { 4, 0 }; // 4s
-#define BNE_CONN_TIMEOUT 5000 // 5s
#define BNE_CONN_ATTEMPT 3
#define BNE_HDELAY_TYPE_MIN 150 // 150ms
@@ -434,7 +433,7 @@ static bool bne_do_connect (
pfd.fd = *fd;
pfd.events = POLLOUT;
- f_ret = prne_pth_poll(&pfd, 1, BNE_CONN_TIMEOUT, ev);
+ f_ret = prne_pth_poll(&pfd, 1, -1, ev);
if (f_ret > 0) {
socklen_t sl = sizeof(int);
int sov = 0;
@@ -1831,11 +1830,16 @@ static bool bne_do_vec_htbt (prne_bne_t *ctx) {
*
* - Check the program version and update if necessary via PRNE_HTBT_OP_NY_BIN
*/
+ prne_pth_reset_timer(&ev, &BNE_SCK_OP_TIMEOUT);
+ if (prne_mbedtls_pth_handle(&ssl, mbedtls_ssl_close_notify, fd, ev)) {
+ prne_shutdown(fd, SHUT_RDWR);
+ }
}
END: // CATCH
mbedtls_ssl_free(&ssl);
prne_close(fd);
+ pth_event_free(ev, FALSE);
return ret;
}