diff options
author | Test_User <hax@andrewyu.org> | 2024-06-19 03:41:14 -0400 |
---|---|---|
committer | Test_User <hax@andrewyu.org> | 2024-06-19 03:41:14 -0400 |
commit | 991d1d37474726ae5dc910da9705485f7b193e18 (patch) | |
tree | e6d01a7a65dd8f916f400f1b083909c58a304d71 /networks/plaintext_buffered.c | |
parent | 9c16070679fea6ac5625546d4ba5af0f638e6636 (diff) | |
download | haxircd-991d1d37474726ae5dc910da9705485f7b193e18.tar.gz haxircd-991d1d37474726ae5dc910da9705485f7b193e18.zip |
Some improvements and openssl send buffering
Diffstat (limited to 'networks/plaintext_buffered.c')
-rw-r--r-- | networks/plaintext_buffered.c | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/networks/plaintext_buffered.c b/networks/plaintext_buffered.c index 6ac3e1c..99bd085 100644 --- a/networks/plaintext_buffered.c +++ b/networks/plaintext_buffered.c @@ -65,27 +65,31 @@ struct plaintext_buffered_handle { size_t buffer_len; }; +int init_plaintext_buffered_network(void) { + return 0; +} + void * plaintext_buffered_send_thread(void *handle) { struct plaintext_buffered_handle *info = handle; size_t read_buffer_index = 0; mutex_lock(&(info->mutex)); while (1) { + if (!info->valid) + goto plaintext_buffered_send_thread_error_unlock; + size_t len; len = info->buffer_len; #ifdef USE_FUTEX + mutex_unlock(&(info->release_write)); if (len == 0) info->release_read = 1; - mutex_unlock(&(info->release_write)); #else sem_trywait(&(info->release_write)); sem_post(&(info->release_write)); #endif - if (!info->valid) - goto plaintext_buffered_send_thread_error_unlock; - mutex_unlock(&(info->mutex)); #ifdef USE_FUTEX @@ -132,7 +136,6 @@ void * plaintext_buffered_send_thread(void *handle) { sem_trywait(&(info->release_write)); sem_post(&(info->release_write)); #endif - // TODO: Sane solution that works with ptread mutexes while (1) { mutex_lock(&(info->mutex)); if (info->close) { @@ -165,10 +168,6 @@ void * plaintext_buffered_send_thread(void *handle) { return 0; } -int init_plaintext_buffered_network(void) { - return 0; -} - int plaintext_buffered_send(void *handle, struct string msg) { struct plaintext_buffered_handle *plaintext_handle = handle; while (msg.len > 0) { @@ -197,9 +196,6 @@ int plaintext_buffered_send(void *handle, struct string msg) { } #endif memcpy(&(plaintext_handle->buffer[plaintext_handle->write_buffer_index]), msg.data, len); - plaintext_handle->write_buffer_index += len; - if (plaintext_handle->write_buffer_index >= PLAINTEXT_BUFFERED_LEN) - plaintext_handle->write_buffer_index = 0; plaintext_handle->buffer_len += len; #ifdef USE_FUTEX mutex_unlock(&(plaintext_handle->release_read)); @@ -208,7 +204,11 @@ int plaintext_buffered_send(void *handle, struct string msg) { sem_post(&(plaintext_handle->release_read)); #endif mutex_unlock(&(plaintext_handle->mutex)); + plaintext_handle->write_buffer_index += len; + if (plaintext_handle->write_buffer_index >= PLAINTEXT_BUFFERED_LEN) + plaintext_handle->write_buffer_index = 0; msg.len -= len; + msg.data += len; } return 0; @@ -268,6 +268,7 @@ int plaintext_buffered_connect(void **handle, struct string address, struct stri goto plaintext_buffered_connect_close; *handle = plaintext_handle; plaintext_handle->valid = 1; + plaintext_handle->close = 0; plaintext_handle->fd = fd; addr_out->data = malloc(sizeof(sockaddr)); @@ -335,7 +336,7 @@ int plaintext_buffered_accept(int listen_fd, void **handle, struct string *addr) goto plaintext_buffered_accept_close; *handle = plaintext_handle; plaintext_handle->valid = 1; - plaintext_handle->close = 1; + plaintext_handle->close = 0; plaintext_handle->fd = con_fd; addr->data = malloc(address_len); |