From 202f457fe8163fe079e597d8888eaca9997c1c07 Mon Sep 17 00:00:00 2001 From: a Date: Fri, 4 Aug 2023 02:58:17 -0400 Subject: [PATCH] Fixed broken networking --- oct_networking.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/oct_networking.c b/oct_networking.c index 1ee94cb..7628171 100644 --- a/oct_networking.c +++ b/oct_networking.c @@ -24,7 +24,7 @@ struct { int sfd; } oct_network_node; -// Address book currently implemented as a doubly-linked list with O(n) inserts, accesses +// Address book currently implemented as a doubly-linked list with O(1) inserts, O(n) accesses // Ideal implementation is hash table with O(1) inserts, accesses // However, we'll see if this works for now struct { @@ -73,7 +73,7 @@ static int oct_network_init_socket(char* addr, char* port) { OCT_LOG_WARNING("Could not connect to %s:%s", addr, port); return -1; } - return s; + return sfd; } int oct_network_node_init(char* port, lua_State* L) { @@ -174,7 +174,7 @@ int oct_network_send_msg() { int sfd = e->sfd; ssize_t length = strlen(oct_network_node.send_buffer); - OCT_LOG_INFO("Sending message"); + OCT_LOG_DEBUG("Sending message: %s", oct_network_node.send_buffer); if (write(sfd, oct_network_node.send_buffer, length) != length) { OCT_LOG_WARNING("Partial write when sending message"); return -1; @@ -222,11 +222,12 @@ struct oct_network_ab_entry* oct_network_ab_insert(char* addr, char* port) { } // Then, create the socket - if ((e->sfd = oct_network_init_socket(addr, port)) < 0) { + e->sfd = oct_network_init_socket(addr, port); + if (e->sfd < 0) { free(e); return NULL; } - OCT_LOG_INFO("CREATED NEW SOCKET"); + OCT_LOG_INFO("Created new socket for %s:%s", addr, port); e->next = NULL; e->prev = oct_network_ab.last; strncpy(e->addr, addr, NI_MAXHOST);