Skip to content

Commit c854fc6

Browse files
committed
Waiting the tcp socket closed by remote client
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]
1 parent 6f93c0e commit c854fc6

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

jerry-ext/debugger/debugger-tcp.c

+24
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,30 @@ jerryx_debugger_tcp_close (jerry_debugger_transport_header_t *header_p) /**< tcp
146146

147147
jerryx_debugger_transport_tcp_t *tcp_p = (jerryx_debugger_transport_tcp_t *) header_p;
148148

149+
/* Waiting for the debug client close the tcp connection first. */
150+
while (true)
151+
{
152+
char buf[8];
153+
jerryx_socket_ssize_t result = recv (tcp_p->tcp_socket, buf, sizeof (buf), 0);
154+
if (result == 0)
155+
{
156+
/**
157+
* If result == 0, means the socket are closed by remote client, break the loop
158+
*/
159+
break;
160+
}
161+
else if (result < 0 && jerryx_debugger_tcp_get_errno () != JERRYX_EWOULDBLOCK)
162+
{
163+
/* errno other than JERRYX_EWOULDBLOCK means socket have true error, break the loop */
164+
break;
165+
}
166+
/**
167+
* If result > 0, means that there is data available on the socket, waiting.
168+
* If result < 0 and errno == JERRYX_EWOULDBLOCK, means have no data but
169+
* the socket still available, waiting.
170+
*/
171+
}
172+
149173
JERRYX_DEBUG_MSG ("TCP connection closed.\n");
150174

151175
jerryx_debugger_tcp_close_socket (tcp_p->tcp_socket);

0 commit comments

Comments
 (0)