~ chicken-core (chicken-5) 6f08865afdbbeec4f376d5b8a7d3c2f4c6e0f6f8
commit 6f08865afdbbeec4f376d5b8a7d3c2f4c6e0f6f8 Author: Evan Hanson <evhan@foldling.org> AuthorDate: Thu Mar 14 21:42:47 2019 +1300 Commit: felix <felix@call-with-current-continuation.org> CommitDate: Thu Mar 14 10:38:29 2019 +0100 Avoid spin loop in socket_read() when debug client disconnects Signed-off-by: felix <felix@call-with-current-continuation.org> diff --git a/dbg-stub.c b/dbg-stub.c index 348a77f6..218d8506 100644 --- a/dbg-stub.c +++ b/dbg-stub.c @@ -159,7 +159,7 @@ socket_read() if(*(input_buffer_top++) == '\n') { *ptr = '\0'; --input_buffer_len; - return 0; + return 1; } if(++off >= RW_BUFFER_SIZE) return -1; /* read-buffer overflow */ @@ -171,6 +171,8 @@ socket_read() if(n == SOCKET_ERROR) return -1; /* read failed */ + if(n == 0) return 0; /* client disconnect */ + input_buffer_len = n; input_buffer_top = input_buffer; } @@ -304,7 +306,11 @@ send_event(int event, C_char *loc, C_char *val, C_char *cloc) send_string_value(cloc); send_string(")\n"); - if(socket_read() < 0) terminate("read failed"); + n = socket_read(); + + if(n < 0) terminate("read failed"); + + if(n == 0) terminate("debugger disconnected"); /* fprintf(stderr, "<READ: %s>\n", rw_buffer); */ n = sscanf(rw_buffer, "(%d ", &reply);Trap