diff options
author | Test_User <hax@andrewyu.org> | 2024-07-22 23:11:54 -0400 |
---|---|---|
committer | Test_User <hax@andrewyu.org> | 2024-07-22 23:11:54 -0400 |
commit | 74ebc09736f85fb72a5bcdc96b93ae50cf86652d (patch) | |
tree | b4d3811cd565d64053b6baff2adcde17812e73bb | |
parent | e859880db83c5120670b87c1d5a8cf03eedc1806 (diff) | |
download | haxircd-74ebc09736f85fb72a5bcdc96b93ae50cf86652d.tar.gz haxircd-74ebc09736f85fb72a5bcdc96b93ae50cf86652d.zip |
Bit of improvement on error handling for networking
-rw-r--r-- | mutex.h | 2 | ||||
-rw-r--r-- | networks/openssl.c | 14 | ||||
-rw-r--r-- | networks/openssl_buffered.c | 14 | ||||
-rw-r--r-- | networks/plaintext.c | 2 | ||||
-rw-r--r-- | networks/plaintext_buffered.c | 2 |
5 files changed, 33 insertions, 1 deletions
@@ -98,7 +98,7 @@ inline void mutex_lock(sem_t *mutex) { } inline void mutex_unlock(sem_t *mutex) { - sem_trywait(mutex); + while (sem_trywait(mutex) == -1 && errno == EINTR); sem_post(mutex); } diff --git a/networks/openssl.c b/networks/openssl.c index bf6b869..d2b84b1 100644 --- a/networks/openssl.c +++ b/networks/openssl.c @@ -148,6 +148,20 @@ size_t openssl_recv(void *handle, char *data, size_t len, char *err) { case SSL_ERROR_WANT_WRITE: pollfd.events = POLLOUT; break; + case SSL_ERROR_ZERO_RETURN: + mutex_unlock(&(openssl_handle->mutex)); + *err = 2; + return 0; + case SSL_ERROR_SYSCALL: + mutex_unlock(&(openssl_handle->mutex)); + + if (errno == ESHUTDOWN || errno == ECONNRESET) { + *err = 2; + } else { + *err = 3; + } + + return 0; default: mutex_unlock(&(openssl_handle->mutex)); *err = 3; diff --git a/networks/openssl_buffered.c b/networks/openssl_buffered.c index 78d2830..47057aa 100644 --- a/networks/openssl_buffered.c +++ b/networks/openssl_buffered.c @@ -265,6 +265,20 @@ size_t openssl_buffered_recv(void *handle, char *data, size_t len, char *err) { case SSL_ERROR_WANT_WRITE: pollfd.events = POLLOUT; break; + case SSL_ERROR_ZERO_RETURN: + mutex_unlock(&(openssl_handle->mutex)); + *err = 2; + return 0; + case SSL_ERROR_SYSCALL: + mutex_unlock(&(openssl_handle->mutex)); + + if (errno == ESHUTDOWN || errno == ECONNRESET) { + *err = 2; + } else { + *err = 3; + } + + return 0; default: mutex_unlock(&(openssl_handle->mutex)); *err = 3; diff --git a/networks/plaintext.c b/networks/plaintext.c index 56c06fb..0bc17a6 100644 --- a/networks/plaintext.c +++ b/networks/plaintext.c @@ -72,6 +72,8 @@ size_t plaintext_recv(void *fd, char *data, size_t len, char *err) { if (res == -1) { if (errno == EAGAIN || errno == EWOULDBLOCK) { *err = 1; + } else if (errno == ESHUTDOWN || errno == ECONNRESET) { + *err = 2; } else { *err = 3; } diff --git a/networks/plaintext_buffered.c b/networks/plaintext_buffered.c index d8cfc77..5fea3bd 100644 --- a/networks/plaintext_buffered.c +++ b/networks/plaintext_buffered.c @@ -205,6 +205,8 @@ size_t plaintext_buffered_recv(void *handle, char *data, size_t len, char *err) if (res == -1) { if (errno == EAGAIN || errno == EWOULDBLOCK) { *err = 1; + } else if (errno == ESHUTDOWN || errno == ECONNRESET) { + *err = 2; } else { *err = 3; } |