summaryrefslogtreecommitdiff
path: root/core/network.h
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-08-20 17:07:55 -0700
committerirungentoo <irungentoo@gmail.com>2013-08-20 17:07:55 -0700
commitc12853275c03ca6153c9424f29220bc5b8903875 (patch)
treed8191c6a088bcaf8c908fbb5e81a22825712330f /core/network.h
parent617b2c8ba59970a67178c602d5348d036140d559 (diff)
parent128223d9d1c70afe0adb4cfe0cfda39204379c3a (diff)
Merge pull request #506 from irungentoo/refactor
Refactored Everything.
Diffstat (limited to 'core/network.h')
-rw-r--r--core/network.h23
1 files changed, 17 insertions, 6 deletions
diff --git a/core/network.h b/core/network.h
index 127a55d1..87f45978 100644
--- a/core/network.h
+++ b/core/network.h
@@ -99,7 +99,18 @@ 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
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;
103 114
104/* returns current time in milleseconds since the epoch. */ 115/* returns current time in milleseconds since the epoch. */
105uint64_t current_time(void); 116uint64_t current_time(void);
@@ -111,13 +122,13 @@ uint32_t random_int(void);
111/* Basic network functions: */ 122/* Basic network functions: */
112 123
113/* Function to send packet(data) of length length to ip_port */ 124/* Function to send packet(data) of length length to ip_port */
114int sendpacket(IP_Port ip_port, uint8_t *data, uint32_t length); 125int sendpacket(int sock, IP_Port ip_port, uint8_t *data, uint32_t length);
115 126
116/* Function to call when packet beginning with byte is received */ 127/* Function to call when packet beginning with byte is received */
117void networking_registerhandler(uint8_t byte, packet_handler_callback cb); 128void networking_registerhandler(Networking_Core *net, uint8_t byte, packet_handler_callback cb, void *object);
118 129
119/* call this several times a second */ 130/* call this several times a second */
120void networking_poll(); 131void networking_poll(Networking_Core *net);
121 132
122/* initialize networking 133/* initialize networking
123 bind to ip and port 134 bind to ip and port
@@ -125,10 +136,10 @@ void networking_poll();
125 port is in host byte order (this means don't worry about it) 136 port is in host byte order (this means don't worry about it)
126 returns 0 if no problems 137 returns 0 if no problems
127 returns -1 if there were problems */ 138 returns -1 if there were problems */
128int init_networking(IP ip, uint16_t port); 139Networking_Core *new_networking(IP ip, uint16_t port);
129 140
130/* function to cleanup networking stuff(doesn't do much right now) */ 141/* function to cleanup networking stuff(doesn't do much right now) */
131void shutdown_networking(void); 142void kill_networking(Networking_Core *net);
132 143
133/* 144/*
134 resolve_addr(): 145 resolve_addr():