ioLibrary_Driver icon indicating copy to clipboard operation
ioLibrary_Driver copied to clipboard

socket.c listen() bug

Open DmitryGostev opened this issue 3 years ago • 1 comments

The bug occurs when the client connects instantly after listen(), getSn_SR(sn) never returns SOCK_LISTEN, but returns SOCK_ESTABLISHED. In this case listen() calls close(sn) and returns SOCKERR_SOCKCLOSED.

Possible fix: socket.c, int8_t listen(uint8_t sn) changing code

while(getSn_SR(sn) != SOCK_LISTEN) { close(sn); return SOCKERR_SOCKCLOSED; }

to

============================== uint8_t res;

.....

res=getSn_SR(sn); if (res != SOCK_LISTEN && res!=SOCK_ESTABLISHED) { close(sn); return SOCKERR_SOCKCLOSED; }

DmitryGostev avatar Nov 10 '22 06:11 DmitryGostev

The situation you describe, where there might be a delay between calling listen() and checking the socket status using getSn_SR before a TCP connection is established, seems plausible. Although it may not be a common occurrence, we will discuss it internally before deciding to implement it.

Listen() Function image

Serial output

image

irinakim12 avatar Nov 20 '23 07:11 irinakim12