summaryrefslogtreecommitdiff
path: root/input.c
diff options
context:
space:
mode:
authorMikhail Burakov <mburakov@mailbox.org>2024-05-12 15:05:50 +0200
committerMikhail Burakov <mburakov@mailbox.org>2024-05-12 15:05:50 +0200
commitd511fae02fba6f6c8ea2896d5a6cefd8d3337ca3 (patch)
tree966f39c3fe988c96f75e5220cd10e4a8b6fdf0e5 /input.c
parent918682faa29197fe3b0a544906638e02785a6b17 (diff)
Add generic proto writing method
Diffstat (limited to 'input.c')
-rw-r--r--input.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/input.c b/input.c
index e47f363..5a279cc 100644
--- a/input.c
+++ b/input.c
@@ -100,12 +100,11 @@ bool InputHandlerHandle(struct InputHandler* input_handler, int fd) {
// mburakov: Payload of ping message is not yet available.
return true;
}
- char buffer[sizeof(struct Proto) + sizeof(uint64_t)];
- struct Proto* proto = (void*)buffer;
- proto->size = sizeof(uint64_t);
- proto->type = PROTO_TYPE_MISC;
- memcpy(proto->data, &event->u, sizeof(uint64_t));
- if (write(fd, buffer, sizeof(buffer)) != sizeof(buffer)) {
+ struct Proto proto = {
+ .size = sizeof(uint64_t),
+ .type = PROTO_TYPE_MISC,
+ };
+ if (!WriteProto(fd, &proto, &event->u)) {
LOG("Failed to write pong message (%s)", strerror(errno));
return false;
}