summaryrefslogtreecommitdiff
path: root/core/network.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/network.h')
-rw-r--r--core/network.h24
1 files changed, 18 insertions, 6 deletions
diff --git a/core/network.h b/core/network.h
index 127a55d1..5ed25620 100644
--- a/core/network.h
+++ b/core/network.h
@@ -99,8 +99,20 @@ typedef struct {
99/* Function to receive data, ip and port of sender is put into ip_port 99/* Function to receive data, ip and port of sender is put into ip_port
100 the packet data into data 100 the packet data into data
101 the packet length into length. */ 101 the packet length into length. */
102typedef int (*packet_handler_callback)(IP_Port ip_port, uint8_t *data, uint32_t len); 102typedef int (*packet_handler_callback)(void * object, IP_Port ip_port, uint8_t *data, uint32_t len);
103 103
104typedef struct {
105 packet_handler_callback function;
106 void * object;
107}Packet_Handles;
108
109typedef struct {
110 Packet_Handles packethandlers[256];
111 /* our UDP socket */
112 int sock;
113}Networking_Core;
114
115Networking_Core * temp_net;
104/* returns current time in milleseconds since the epoch. */ 116/* returns current time in milleseconds since the epoch. */
105uint64_t current_time(void); 117uint64_t current_time(void);
106 118
@@ -111,13 +123,13 @@ uint32_t random_int(void);
111/* Basic network functions: */ 123/* Basic network functions: */
112 124
113/* Function to send packet(data) of length length to ip_port */ 125/* Function to send packet(data) of length length to ip_port */
114int sendpacket(IP_Port ip_port, uint8_t *data, uint32_t length); 126int sendpacket(int sock, IP_Port ip_port, uint8_t *data, uint32_t length);
115 127
116/* Function to call when packet beginning with byte is received */ 128/* Function to call when packet beginning with byte is received */
117void networking_registerhandler(uint8_t byte, packet_handler_callback cb); 129void networking_registerhandler(Networking_Core * net, uint8_t byte, packet_handler_callback cb, void * object);
118 130
119/* call this several times a second */ 131/* call this several times a second */
120void networking_poll(); 132void networking_poll(Networking_Core * net);
121 133
122/* initialize networking 134/* initialize networking
123 bind to ip and port 135 bind to ip and port
@@ -125,10 +137,10 @@ void networking_poll();
125 port is in host byte order (this means don't worry about it) 137 port is in host byte order (this means don't worry about it)
126 returns 0 if no problems 138 returns 0 if no problems
127 returns -1 if there were problems */ 139 returns -1 if there were problems */
128int init_networking(IP ip, uint16_t port); 140Networking_Core * new_networking(IP ip, uint16_t port);
129 141
130/* function to cleanup networking stuff(doesn't do much right now) */ 142/* function to cleanup networking stuff(doesn't do much right now) */
131void shutdown_networking(void); 143void kill_networking(Networking_Core * net);
132 144
133/* 145/*
134 resolve_addr(): 146 resolve_addr():