From 4f8be499ef24bfee235212d625f318e75ecd599e Mon Sep 17 00:00:00 2001 From: koekeishiya Date: Sat, 14 Nov 2020 02:51:32 +0100 Subject: [PATCH] #714 *read* does not work as expected on macOS Big Sur ?? --- src/misc/socket.c | 13 +++++++++++++ src/yabai.c | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/misc/socket.c b/src/misc/socket.c index 693392c7..991061c3 100644 --- a/src/misc/socket.c +++ b/src/misc/socket.c @@ -14,6 +14,19 @@ char *socket_read(int sockfd, int *len) result = temp; memcpy(result+cursor, buffer, bytes_read); cursor += bytes_read; + + if (((result+cursor)[-1] == '\0') && + ((result+cursor)[-2] == '\0')) { + + // NOTE(koekeishiya): if our message ends with double null-terminator we + // have successfully received the entire message. this was added because + // on macOS Big Sur we would in a few rare cases read the message AND YET + // still enter another call to *read* above that would block, because the + // client was finished sending its message and is blocking in a poll loop + // waiting for a response. + + break; + } } if (result && bytes_read != -1) { diff --git a/src/yabai.c b/src/yabai.c index dacee39f..8f8b0c3d 100644 --- a/src/yabai.c +++ b/src/yabai.c @@ -66,7 +66,7 @@ static int client_send_message(int argc, char **argv) error("yabai-msg: failed to connect to socket..\n"); } - int message_length = argc - 1; + int message_length = argc; int argl[argc]; for (int i = 1; i < argc; ++i) { @@ -82,6 +82,7 @@ static int client_send_message(int argc, char **argv) temp += argl[i]; *temp++ = '\0'; } + *temp++ = '\0'; if (!socket_write_bytes(sockfd, message, message_length)) { error("yabai-msg: failed to send data..\n");