net: sockets: Return EINVAL when an accept call is unblocked
Under Linux when you shutdown a socket which is blocked on an accept call the error code returned by accept is EINVAL. Modify the socket code to be inline with this behaviour. Signed-off-by: Léonard Bise <leonard.bise@gmail.com>
This commit is contained in:
parent
5cedb73555
commit
8e4faab30a
1 changed files with 15 additions and 1 deletions
|
@ -465,7 +465,21 @@ int zsock_accept_ctx(struct net_context *parent, struct sockaddr *addr,
|
||||||
ctx = k_fifo_get(&parent->accept_q, timeout);
|
ctx = k_fifo_get(&parent->accept_q, timeout);
|
||||||
if (ctx == NULL) {
|
if (ctx == NULL) {
|
||||||
z_free_fd(fd);
|
z_free_fd(fd);
|
||||||
errno = EAGAIN;
|
if (K_TIMEOUT_EQ(timeout, K_NO_WAIT)) {
|
||||||
|
/* For non-blocking sockets return EAGAIN because it
|
||||||
|
* just means the fifo is empty at this time
|
||||||
|
*/
|
||||||
|
errno = EAGAIN;
|
||||||
|
} else {
|
||||||
|
/* For blocking sockets return EINVAL because it means
|
||||||
|
* the socket was closed while we were waiting for
|
||||||
|
* connections. This is the same error code returned
|
||||||
|
* under Linux when calling shutdown on a blocked accept
|
||||||
|
* call
|
||||||
|
*/
|
||||||
|
errno = EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue