From ee553c9a509bed6f74021839a9c40dc81e2838a8 Mon Sep 17 00:00:00 2001 From: Sid Price Date: Sat, 11 Jan 2020 08:47:02 -0700 Subject: [PATCH] Corrected error checking for socket functions (#577) --- src/platforms/pc/gdb_if.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/platforms/pc/gdb_if.c b/src/platforms/pc/gdb_if.c index 6a81a0d..e00cf3a 100644 --- a/src/platforms/pc/gdb_if.c +++ b/src/platforms/pc/gdb_if.c @@ -115,11 +115,19 @@ unsigned char gdb_if_getchar(void) while(1) { gdb_if_conn = accept(gdb_if_serv, NULL, NULL); if (gdb_if_conn == -1) { +#if defined(_WIN32) || defined(__CYGWIN__) + if (WSAGetLastError() == WSAEWOULDBLOCK) { +#else if (errno == EWOULDBLOCK) { +#endif SET_IDLE_STATE(1); platform_delay(100); } else { +#if defined(_WIN32) || defined(__CYGWIN__) + DEBUG("error when accepting connection: %d", WSAGetLastError()); +#else DEBUG("error when accepting connection: %s", strerror(errno)); +#endif exit(1); } } else { @@ -144,7 +152,11 @@ unsigned char gdb_if_getchar(void) i = recv(gdb_if_conn, (void*)&ret, 1, 0); if(i <= 0) { gdb_if_conn = -1; +#if defined(_WIN32) || defined(__CYGWIN__) + DEBUG("Dropped broken connection: %d\n", WSAGetLastError()); +#else DEBUG("Dropped broken connection: %s\n", strerror(errno)); +#endif /* Return '+' in case we were waiting for an ACK */ return '+'; }