From ac1f2aaadd927e8187edabaea9a788425bb42b9f Mon Sep 17 00:00:00 2001 From: Test_User Date: Tue, 8 Aug 2023 22:46:35 -0400 Subject: Hopefully disconnect on its own when things break now --- main.c | 15 ++++++++++++--- server_network.c | 4 ++-- tls.c | 4 +++- tls.h | 4 +++- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/main.c b/main.c index 0fdd429..6d29836 100644 --- a/main.c +++ b/main.c @@ -230,9 +230,18 @@ int main(void) { struct string full_msg = {malloc(0), 0}; while (1) { char data[512]; - pthread_mutex_unlock(&send_lock); - uint64_t new_len = RECV(data, sizeof(data)); - pthread_mutex_lock(&send_lock); + + char timeout; + uint64_t new_len; + while (1) { + pthread_mutex_unlock(&send_lock); + new_len = RECV(data, sizeof(data), &timeout); + pthread_mutex_lock(&send_lock); + if (!timeout) + break; + + SEND(STRING("")); + } if (new_len == 0) { WRITES(1, STRING("Disconnected.\n")); diff --git a/server_network.c b/server_network.c index 14e7ffc..eb9dbee 100644 --- a/server_network.c +++ b/server_network.c @@ -378,7 +378,7 @@ int quit_handler(struct string sender, uint64_t argc, struct string *argv) { } } - remove_table_index(chan_info->user_list, sender); + remove_table_index(&(chan_info->user_list), sender); } free(info->server.data); @@ -839,7 +839,7 @@ int part_handler(struct string sender, uint64_t argc, struct string *argv) { } if (channel) - remove_table_index(channel->user_list, sender); + remove_table_index(&(channel->user_list), sender); return 0; } diff --git a/tls.c b/tls.c index 54cf47d..314a889 100644 --- a/tls.c +++ b/tls.c @@ -84,7 +84,9 @@ int connect_tls(void) { if (ret < 0) return 10; + gnutls_record_set_timeout(session, 60000); // 60s + return 0; } -extern inline size_t RECV(char *buf, size_t buflen); // Should force it to get compiled into tls.o +extern inline size_t RECV(char *buf, size_t buflen, char *timeout); // Should force it to get compiled into tls.o diff --git a/tls.h b/tls.h index 116512d..577251b 100644 --- a/tls.h +++ b/tls.h @@ -34,11 +34,13 @@ extern gnutls_session_t session; extern int connect_tls(void); -inline size_t RECV(char *buf, size_t buflen) { +inline size_t RECV(char *buf, size_t buflen, char *timeout) { int len; do { len = gnutls_record_recv(session, buf, buflen); } while (len == GNUTLS_E_AGAIN || len == GNUTLS_E_INTERRUPTED); + + *timeout = (len == GNUTLS_E_TIMEDOUT); if (len < 0) return 0; else -- cgit v1.2.3