Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a792221

Browse files
committedJan 23, 2021
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 1db0905 commit a792221

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
 

‎jerry-ext/debugger/debugger-tcp.c

+21
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,27 @@ 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+
148+
/* Waiting the debug client close the tcp connection first */
149+
for (;;)
150+
{
151+
char buf[8];
152+
jerryx_socket_ssize_t result = recv (tcp_p->tcp_socket, buf, sizeof (buf), 0);
153+
if (result == 0)
154+
{
155+
/**
156+
* If result >= 0, this means that there is either data available on the socket, or the socket
157+
* has been closed. So waiting the socket closed by remote client by result == 0
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 */
164+
break;
165+
}
166+
}
167+
147168
JERRYX_DEBUG_MSG ("TCP connection closed.\n");
148169

149170
jerryx_debugger_tcp_close_socket (tcp_p->tcp_socket);

0 commit comments

Comments
 (0)
Please sign in to comment.