30#define inet_ntop InetNtop
31typedef SSIZE_T ssize_t;
35#define INVALID_SOCKET -1
67#define PTR(addr) ((char *) (addr))
70#define O2N_MESSAGE_EXTRA (offsetof(O2netmsg, payload))
73#define O2N_MESSAGE_SIZE_FROM_DATA_SIZE(len) ((len) + O2N_MESSAGE_EXTRA)
74#define O2N_MESSAGE_ALLOC(len) \
75 ((O2netmsg_ptr) O2_MALLOC(O2N_MESSAGE_SIZE_FROM_DATA_SIZE(len)))
79#define NET_UDP_SERVER (O2TAG_HIGH << 1)
82#define NET_TCP_SERVER (O2TAG_HIGH << 2)
85#define NET_TCP_CONNECTING (O2TAG_HIGH << 3)
88#define NET_TCP_CLIENT (O2TAG_HIGH << 4)
91#define NET_TCP_CONNECTION (O2TAG_HIGH << 5)
94#define NET_INFO_CLOSED (O2TAG_HIGH << 6)
97#define NET_INFILE (O2TAG_HIGH << 7)
103#define NET_TCP_MASK (NET_TCP_SERVER | NET_TCP_CLIENT | NET_TCP_CONNECTION)
107 struct sockaddr_in sa;
109 O2err init(
const char *ip,
int port_num,
bool tcp_flag);
110 O2err init_hex(
const char *ip,
int port_num,
bool tcp_flag);
111 int get_port() {
return ntohs(sa.sin_port); }
112 void set_port(
int port) { sa.sin_port = htons(port); }
113 struct sockaddr *get_sockaddr() {
return (
struct sockaddr *) &sa; }
114 struct in_addr *get_in_addr() {
return &sa.sin_addr; }
115 const char *to_dot(
char *ip) {
116 return inet_ntop(AF_INET, get_in_addr(), ip, O2N_IP_LEN); }
125 virtual O2err connected() {
126 printf(
"ERROR: connected called by mistake\n");
return O2_FAIL; }
138 virtual void remove() = 0;
141typedef enum {READ_O2, READ_RAW, READ_CUSTOM} Read_type;
142typedef enum {WRITE_O2, WRITE_CUSTOM} Write_type;
170 Write_type write_type;
194 void set_events(
short events);
197 static Fds_info *create_tcp_client(
const char *ip,
int port,
206 static Fds_info *create_udp_server(
int *port,
bool reuse);
209 O2err connect(
const char *ip,
int tcp_port);
227 O2err send(
bool block);
229 int read_event_handler();
230 O2err read_whole_message(SOCKET sock);
231 void message_cleanup();
232 Fds_info *cleanup(
const char *error, SOCKET sock);
234 void close_socket(
bool now);
237 static const char *tag_to_string(
int tag);
244extern bool o2n_network_enabled;
245extern bool o2n_network_found;
247extern char o2n_public_ip[O2N_IP_LEN];
248extern char o2n_internal_ip[O2N_IP_LEN];
251O2err o2n_initialize();
256void o2n_finish(
void);
267void o2n_free_deleted_sockets(
void);
277#define o2n_send_udp_via_info(info, ua, msg) \
278 o2n_send_udp_via_socket(info->get_socket(), ua, msg);
286SOCKET o2n_broadcast_socket_new();
289SOCKET o2n_udp_send_socket_new();
291SOCKET o2n_tcp_socket_new();
293void o2_disable_sigpipe(SOCKET sock);
Definition: o2network.h:147
Definition: o2network.h:105
Definition: o2network.h:121
O2err
return values used generally by O2 functions
Definition: o2.h:329
@ O2_SUCCESS
function was successful
Definition: o2.h:332
@ O2_FAIL
a non-specific error occurred.
Definition: o2.h:339
Definition: o2network.h:57
int64_t pad_if_needed
make sure allocated is 8-byte aligned
Definition: o2network.h:60
struct O2netmsg * next
link for application use
Definition: o2network.h:59
int32_t length
length of message in data part
Definition: o2network.h:62
char payload[4]
data
Definition: o2network.h:63