Fixed bug where messages were mangled in reception
This commit is contained in:
parent
0d2a9150a4
commit
3d3155fc46
|
@ -214,8 +214,11 @@ int oct_network_recv_msgs() {
|
||||||
// recvfrom returns -1 if nothing was received
|
// recvfrom returns -1 if nothing was received
|
||||||
// Need MSG_DONTWAIT flag for nonblocking
|
// Need MSG_DONTWAIT flag for nonblocking
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (recvfrom(oct_network_node.sfd, tmp_buffer, BUFFER_SIZE, MSG_DONTWAIT, (struct sockaddr *) &peer_addr, &peer_addrlen) > 0 && i < OCT_NETWORK_MAX_RECVS) {
|
ssize_t msg_size = recvfrom(oct_network_node.sfd, tmp_buffer, BUFFER_SIZE-1, MSG_DONTWAIT, (struct sockaddr *) &peer_addr, &peer_addrlen);
|
||||||
OCT_LOG_INFO("Received message!");
|
while ((msg_size > 0) && (i < OCT_NETWORK_MAX_RECVS)) {
|
||||||
|
// recvfrom does NOT place the null byte - place it ourselves
|
||||||
|
tmp_buffer[msg_size] = '\0';
|
||||||
|
OCT_LOG_DEBUG("Received message!");
|
||||||
int s = getnameinfo((struct sockaddr *) &peer_addr,
|
int s = getnameinfo((struct sockaddr *) &peer_addr,
|
||||||
peer_addrlen, tmp_addr, NI_MAXHOST, tmp_port, NI_MAXSERV, NI_NUMERICSERV);
|
peer_addrlen, tmp_addr, NI_MAXHOST, tmp_port, NI_MAXSERV, NI_NUMERICSERV);
|
||||||
if (s != 0) {
|
if (s != 0) {
|
||||||
|
@ -224,6 +227,7 @@ int oct_network_recv_msgs() {
|
||||||
}
|
}
|
||||||
oct_network_q_enqueue(&oct_network_node.recv_queue, tmp_addr, tmp_port, tmp_buffer);
|
oct_network_q_enqueue(&oct_network_node.recv_queue, tmp_addr, tmp_port, tmp_buffer);
|
||||||
i++;
|
i++;
|
||||||
|
msg_size = recvfrom(oct_network_node.sfd, tmp_buffer, BUFFER_SIZE-1, MSG_DONTWAIT, (struct sockaddr *) &peer_addr, &peer_addrlen);
|
||||||
}
|
}
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,9 +15,9 @@ end
|
||||||
|
|
||||||
counter = 0;
|
counter = 0;
|
||||||
function oct_loop(key)
|
function oct_loop(key)
|
||||||
if counter == 1000000 then
|
if counter == 10000000 then
|
||||||
oct_send("First message!", "127.0.0.1", "1234");
|
oct_send("First message!\nnewline\nnewline\nnewline", "127.0.0.1", "1234");
|
||||||
oct_send("Second message!", "127.0.0.1", "1234");
|
oct_send("Second message!\nhey!", "127.0.0.1", "1234");
|
||||||
counter = 0;
|
counter = 0;
|
||||||
end
|
end
|
||||||
counter = counter + 1;
|
counter = counter + 1;
|
||||||
|
|
Loading…
Reference in New Issue