diff options
Diffstat (limited to '')
-rw-r--r-- | main.c | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -39,16 +39,20 @@ #include "types.h" void *client_loop(void *ign) { + pthread_mutex_lock(&send_lock); while (1) { struct string full_msg = {.data = malloc(0), .len = 0}; - WRITES(1, STRING("Yay\n")); + pthread_mutex_unlock(&send_lock); client_fd = accept(client_listen_fd, NULL, NULL); + pthread_mutex_lock(&send_lock); listen(client_listen_fd, 0); client_connected = 0; client_nick.data = malloc(0); while (1) { char data[512]; + pthread_mutex_unlock(&send_lock); // TODO: proper locking, this works for now but is certainly inefficient uint64_t new_len = read(client_fd, data, 512); + pthread_mutex_lock(&send_lock); if (new_len == 0) { goto disconnect_client; @@ -210,10 +214,12 @@ int main(void) { pthread_create(&client_thread_id, NULL, client_loop, NULL); + pthread_mutex_lock(&send_lock); struct string full_msg = {malloc(0), 0}; while (1) { char data[512]; uint64_t new_len; + pthread_mutex_unlock(&send_lock); { int len; do { @@ -224,6 +230,7 @@ int main(void) { else new_len = len; } + pthread_mutex_lock(&send_lock); if (new_len == 0) { WRITES(1, STRING("Disconnected.\n")); |