summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
authorCoren[m] <Break@Ocean>2013-09-11 15:47:29 +0200
committerCoren[m] <Break@Ocean>2013-09-11 15:47:29 +0200
commitbe716af15df6ad8459d91c5779e2598c6b85c9ca (patch)
treec401b2408621047ddb49baeeb75b4c293affab65 /toxcore
parentd35fee43ba7fe131e9c3dcda5167a46eacbf315a (diff)
network.c:
- undo "fixing" the wrong variable - fix the logging in receivepacket()
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/network.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/toxcore/network.c b/toxcore/network.c
index 725ce604..de69bb3a 100644
--- a/toxcore/network.c
+++ b/toxcore/network.c
@@ -148,7 +148,6 @@ static int receivepacket(sock_t sock, IP_Port *ip_port, uint8_t *data, uint32_t
148#else 148#else
149 uint32_t addrlen = sizeof(addr); 149 uint32_t addrlen = sizeof(addr);
150#endif 150#endif
151 uint32_t bufflen = *length;
152 (*(int32_t *)length) = recvfrom(sock, (char *) data, MAX_UDP_PACKET_SIZE, 0, (struct sockaddr *)&addr, &addrlen); 151 (*(int32_t *)length) = recvfrom(sock, (char *) data, MAX_UDP_PACKET_SIZE, 0, (struct sockaddr *)&addr, &addrlen);
153 152
154 if (*(int32_t *)length <= 0) { 153 if (*(int32_t *)length <= 0) {
@@ -187,7 +186,7 @@ static int receivepacket(sock_t sock, IP_Port *ip_port, uint8_t *data, uint32_t
187#endif 186#endif
188 187
189#ifdef LOGGING 188#ifdef LOGGING
190 loglogdata("=>O", data, bufflen, ip_port, *length); 189 loglogdata("=>O", data, MAX_UDP_PACKET_SIZE, ip_port, *length);
191#endif 190#endif
192 191
193 return 0; 192 return 0;
@@ -204,18 +203,14 @@ void networking_poll(Networking_Core *net)
204 IP_Port ip_port; 203 IP_Port ip_port;
205 uint8_t data[MAX_UDP_PACKET_SIZE]; 204 uint8_t data[MAX_UDP_PACKET_SIZE];
206 uint32_t length; 205 uint32_t length;
207 int recverr; 206
208 do { 207 while (receivepacket(net->sock, &ip_port, data, &length) != -1) {
209 length = sizeof(data); 208 if (length < 1) continue;
210 recverr = receivepacket(net->sock, &ip_port, data, &length); 209
211 if (!recverr && (length > 0)) { 210 if (!(net->packethandlers[data[0]].function)) continue;
212 if (!(net->packethandlers[data[0]].function)) 211
213 continue; 212 net->packethandlers[data[0]].function(net->packethandlers[data[0]].object, ip_port, data, length);
214 213 }
215 net->packethandlers[data[0]].function(net->packethandlers[data[0]].object,
216 ip_port, data, length);
217 }
218 } while (recverr != -1);
219} 214}
220 215
221uint8_t at_startup_ran = 0; 216uint8_t at_startup_ran = 0;