Skip to content

Commit

Permalink
Fix handling multiple incoming messages at once
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <[email protected]>
  • Loading branch information
falkTX committed Jul 12, 2024
1 parent b6dc4e0 commit 486955f
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,27 @@ void socket_run(int exit_on_failure)
msgbuffer = buffer;
}

msg.sender_id = clientfd;
msg.data = msgbuffer;
msg.data_size = count;
if (g_receive_cb) g_receive_cb(&msg);
if (g_receive_cb)
{
msg.data = msgbuffer;

while (count != 0)
{
if (*msg.data == '\0')
{
--count;
++msg.data;
continue;
}

msg.sender_id = clientfd;
msg.data_size = strlen(msg.data) + 1;
g_receive_cb(&msg);

count -= msg.data_size;
msg.data += msg.data_size;
}
}

if (msgbuffer != buffer)
free(msgbuffer);
Expand Down

0 comments on commit 486955f

Please sign in to comment.