Skip to content

Commit 18c2040

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 e9df2ca commit 18c2040

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
@@ -144,6 +144,30 @@ jerryx_debugger_tcp_close (jerry_debugger_transport_header_t *header_p) /**< tcp
144144

145145
jerryx_debugger_transport_tcp_t *tcp_p = (jerryx_debugger_transport_tcp_t *) header_p;
146146

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

149173
jerryx_debugger_tcp_close_socket (tcp_p->tcp_socket);

0 commit comments

Comments
 (0)