2023-05-21 18:47:35 -04:00
|
|
|
#ifndef OCT_NETWORKING_H
|
|
|
|
#define OCT_NETWORKING_H
|
|
|
|
|
|
|
|
#include <sys/socket.h>
|
2023-05-26 23:52:57 -04:00
|
|
|
#include <lua5.3/lualib.h>
|
2023-06-04 12:20:57 -04:00
|
|
|
#include <netdb.h>
|
2023-05-21 18:47:35 -04:00
|
|
|
|
|
|
|
#define BUFFER_SIZE 1024
|
2023-06-02 08:25:00 -04:00
|
|
|
#define NUM_BUFFERS 10;
|
2023-05-21 18:47:35 -04:00
|
|
|
|
2023-05-22 09:29:35 -04:00
|
|
|
#define OCT_DEFAULT_PORT "20000"
|
|
|
|
|
2023-05-21 18:47:35 -04:00
|
|
|
|
2023-06-04 12:20:57 -04:00
|
|
|
struct oct_network_ab_entry {
|
|
|
|
int sfd;
|
|
|
|
char addr[NI_MAXHOST];
|
|
|
|
char port[NI_MAXSERV];
|
|
|
|
struct oct_network_ab_entry* next;
|
2023-06-08 22:07:58 -04:00
|
|
|
struct oct_network_ab_entry* prev;
|
2023-06-04 12:20:57 -04:00
|
|
|
};
|
|
|
|
|
2023-05-26 23:52:57 -04:00
|
|
|
int oct_network_node_init(char* port, lua_State* L);
|
2023-05-26 21:20:13 -04:00
|
|
|
int oct_network_node_deinit();
|
2023-06-04 12:20:57 -04:00
|
|
|
|
|
|
|
// These are heavily based off of man 3 getaddrinfo, e.g. at
|
|
|
|
// https://www.man7.org/linux/man-pages/man3/getaddrinfo.3.html
|
2023-05-26 21:20:13 -04:00
|
|
|
int oct_network_recv_msg();
|
|
|
|
int oct_network_send_msg();
|
2023-05-26 23:52:57 -04:00
|
|
|
int oct_network_recv_msg_lua(lua_State* L);
|
|
|
|
int oct_network_send_msg_lua(lua_State* L);
|
|
|
|
|
2023-06-04 12:20:57 -04:00
|
|
|
void oct_network_ab_init();
|
|
|
|
int oct_network_ab_insert(char* addr, char* port);
|
|
|
|
int oct_network_ab_remove(struct oct_network_ab_entry* e);
|
2023-06-08 22:07:58 -04:00
|
|
|
void oct_network_ab_deinit();
|
2023-06-04 12:20:57 -04:00
|
|
|
|
|
|
|
|
2023-05-21 18:47:35 -04:00
|
|
|
#endif
|