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

@@ -139,28 +139,29 @@ handle_client(int sock_fd, IPSockAddr *addr)
static void
handle_helper_request(int fd, int event, void *arg)
{
SCK_Message message;
SCK_Message *message;
HelperRequest *req;
IPSockAddr client_addr;
int sock_fd;
if (!SCK_ReceiveMessage(fd, &message, SCK_FLAG_MSG_DESCRIPTOR))
message = SCK_ReceiveMessage(fd, SCK_FLAG_MSG_DESCRIPTOR);
if (!message)
return;
sock_fd = message.descriptor;
sock_fd = message->descriptor;
if (sock_fd < 0) {
/* Message with no descriptor is a shutdown command */
SCH_QuitProgram();
return;
}
if (message.length != sizeof (HelperRequest)) {
if (message->length != sizeof (HelperRequest)) {
DEBUG_LOG("Unexpected message length");
SCK_CloseSocket(sock_fd);
return;
}
req = message.data;
req = message->data;
/* Extract the server key and client address from the request */
server_keys[current_server_key].id = ntohl(req->key_id);