open-card-table/oct_networking.h

40 lines
1003 B
C

#ifndef OCT_NETWORKING_H
#define OCT_NETWORKING_H
#include <sys/socket.h>
#include <lua5.3/lualib.h>
#include <netdb.h>
#define BUFFER_SIZE 1024
#define NUM_BUFFERS 10;
#define OCT_DEFAULT_PORT "20000"
struct oct_network_ab_entry {
int sfd;
char addr[NI_MAXHOST];
char port[NI_MAXSERV];
struct oct_network_ab_entry* next;
struct oct_network_ab_entry* prev;
};
int oct_network_node_init(char* port, lua_State* L);
int oct_network_node_deinit();
// These are heavily based off of man 3 getaddrinfo, e.g. at
// https://www.man7.org/linux/man-pages/man3/getaddrinfo.3.html
int oct_network_recv_msg();
int oct_network_send_msg();
int oct_network_recv_msg_lua(lua_State* L);
int oct_network_send_msg_lua(lua_State* L);
void oct_network_ab_init();
struct oct_network_ab_entry* oct_network_ab_insert(char* addr, char* port);
int oct_network_ab_remove(struct oct_network_ab_entry* e);
struct oct_network_ab_entry* oct_network_ab_find(char* addr, char* port);
void oct_network_ab_deinit();
#endif