This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

recv() returns BSD_ESOCK on listening socket

Hi,
MDK MDK-Plus 7.18.0 over RTX5, compiled with ARM Compiler 6 in uVision 5

I'm using BSD API in non-blocking mode.

This is a complex project (Mongoose, https://mongoose.ws) but basically the problem is with a TCP server,

Open socket, listen, clients connect, accept, configure socket, read/write, and suddenly one of the sockets starts returning BSD_ESOCK to recv() until it is closed.

I have 10 TCP sockets, 10 BSD sockets, 1 listener, and I call `listen()` with a backlog of 5. I don't have more than 3 simultaneous connections, this mostly happens with the second socket after the third connection

Error checking removed for clarity (but done), these are the calls to MDK-Plus, is there anything wrong with this ?

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
bind(fd, &sa, slen);
listen(fd, 5);
setlocaddr(fd, loc);
unsigned long on = 1;
ioctlsocket(fd, FIONBIO, &on);
rc = select((int) maxfd + 1, &rset, &wset, &eset, 1 second)) < 0)
do {
clear sa
fd = accept(fd, &sa, &sa_len);
} while (fd == BSD_EWOULDBLOCK)
int on = 1;
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *) &on, sizeof(on))
setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (char *) &on, sizeof(on))
n = recv(fd, buf, len, MSG_NONBLOCKING);
n = send(fd, buf, len, MSG_NONBLOCKING);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

0