Skip to content

Commit

Permalink
#714 *read* does not work as expected on macOS Big Sur ??
Browse files Browse the repository at this point in the history
  • Loading branch information
koekeishiya committed Nov 14, 2020
1 parent 5426f25 commit 4f8be49
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/misc/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/yabai.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

This comment has been minimized.

Copy link
@pyrho

pyrho Nov 14, 2020

I knew that looked fishy ! :D

This comment has been minimized.

Copy link
@koekeishiya

koekeishiya Nov 14, 2020

Author Owner

This really shouldn't be necessary though. The shutdown of the write pipe below causes the socket to flush. The bug is that the yabai daemon is stuck in the read loop, after it successfully reads its message.

This comment has been minimized.

Copy link
@koekeishiya

koekeishiya Nov 14, 2020

Author Owner

What I did is basically output another character in the message, so that the yabai daemon can decide on its own when it has read the entire message, instead of relying on the OS / libc read call to correctly track the buffer.

int message_length = argc;
int argl[argc];

for (int i = 1; i < argc; ++i) {
Expand All @@ -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");
Expand Down

0 comments on commit 4f8be49

Please sign in to comment.