socket: simplify receiving messages

Don't require the caller to provide a SCK_Message (on stack). Modify the
SCK_ReceiveMessage*() functions to return a pointer to static buffers,
as the message buffer which SCK_Message points to already is.
This commit is contained in:
Miroslav Lichvar
2020-03-24 15:22:31 +01:00
parent b8b751a932
commit b20ef4cd7f
6 changed files with 62 additions and 51 deletions

View File

@@ -407,7 +407,7 @@ read_from_socket(int sock_fd, int event, void *anything)
/* This should only be called when there is something
to read, otherwise it may block */
SCK_Message messages[SCK_MAX_RECV_MESSAGES];
SCK_Message *messages;
int i, received, flags = 0;
#ifdef HAVE_LINUX_TIMESTAMPING
@@ -423,8 +423,8 @@ read_from_socket(int sock_fd, int event, void *anything)
#endif
}
received = SCK_ReceiveMessages(sock_fd, messages, SCK_MAX_RECV_MESSAGES, flags);
if (received <= 0)
messages = SCK_ReceiveMessages(sock_fd, flags, &received);
if (!messages)
return;
for (i = 0; i < received; i++)