Fixed broken networking

This commit is contained in:
a 2023-08-04 02:58:17 -04:00
parent 27e4c19117
commit 202f457fe8
1 changed files with 6 additions and 5 deletions

View File

@ -24,7 +24,7 @@ struct {
int sfd; int sfd;
} oct_network_node; } 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 // Ideal implementation is hash table with O(1) inserts, accesses
// However, we'll see if this works for now // However, we'll see if this works for now
struct { 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); OCT_LOG_WARNING("Could not connect to %s:%s", addr, port);
return -1; return -1;
} }
return s; return sfd;
} }
int oct_network_node_init(char* port, lua_State* L) { int oct_network_node_init(char* port, lua_State* L) {
@ -174,7 +174,7 @@ int oct_network_send_msg() {
int sfd = e->sfd; int sfd = e->sfd;
ssize_t length = strlen(oct_network_node.send_buffer); 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) { if (write(sfd, oct_network_node.send_buffer, length) != length) {
OCT_LOG_WARNING("Partial write when sending message"); OCT_LOG_WARNING("Partial write when sending message");
return -1; return -1;
@ -222,11 +222,12 @@ struct oct_network_ab_entry* oct_network_ab_insert(char* addr, char* port) {
} }
// Then, create the socket // 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); free(e);
return NULL; return NULL;
} }
OCT_LOG_INFO("CREATED NEW SOCKET"); OCT_LOG_INFO("Created new socket for %s:%s", addr, port);
e->next = NULL; e->next = NULL;
e->prev = oct_network_ab.last; e->prev = oct_network_ab.last;
strncpy(e->addr, addr, NI_MAXHOST); strncpy(e->addr, addr, NI_MAXHOST);