Skip to content

Commit

Permalink
Waiting the tcp socket closed by remote client
Browse files Browse the repository at this point in the history
So that the tcp socket are closed by debugger client first and
the debugger client won't receive socket are closed by remote error

JerryScript-DCO-1.0-Signed-off-by: Yonggang Luo [email protected]
  • Loading branch information
lygstate committed Jan 23, 2021
1 parent 1db0905 commit 496b146
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions jerry-ext/debugger/debugger-tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,25 @@ jerryx_debugger_tcp_close (jerry_debugger_transport_header_t *header_p) /**< tcp

jerryx_debugger_transport_tcp_t *tcp_p = (jerryx_debugger_transport_tcp_t *) header_p;

for (;;)
{
char buf[8];
jerryx_socket_ssize_t result = recv (tcp_p->tcp_socket, buf, sizeof (buf), 0);
if (result == 0)
{
/**
* If result >= 0, this means that there is either data available on the socket, or the socket
* has been closed. So waiting the socket closed by remote client by result == 0
*/
break;
}
else if (result < 0 && jerryx_debugger_tcp_get_errno () != JERRYX_EWOULDBLOCK)
{
/* errno other than JERRYX_EWOULDBLOCK means socket have true error */
break;
}
}

JERRYX_DEBUG_MSG ("TCP connection closed.\n");

jerryx_debugger_tcp_close_socket (tcp_p->tcp_socket);
Expand Down

0 comments on commit 496b146

Please sign in to comment.