Skip to content
Browse files

net: sockets: close: Call net_context_accept only for listening socket

The previous code "optimized" and called both net_context_accept()
and net_context_recv() blindly to reset the corresponding callbacks.
But this leads to "wrong state" logging if debugging is enabled, so
clean that up.

Signed-off-by: Paul Sokolovsky <>
  • Loading branch information...
pfalcon authored and nashif committed Aug 22, 2018
1 parent 9dd63f7 commit 2af8dc963080e07aba8a3162ad45977a372da9c1
Showing with 5 additions and 2 deletions.
  1. +5 −2 subsys/net/lib/sockets/sockets.c
@@ -106,8 +106,11 @@ int _impl_zsock_close(int sock)
* as these are fail-free operations and we're closing
* socket anyway.
(void)net_context_accept(ctx, NULL, K_NO_WAIT, NULL);
(void)net_context_recv(ctx, NULL, K_NO_WAIT, NULL);
if (net_context_get_state(ctx) == NET_CONTEXT_LISTENING) {
(void)net_context_accept(ctx, NULL, K_NO_WAIT, NULL);
} else {
(void)net_context_recv(ctx, NULL, K_NO_WAIT, NULL);


0 comments on commit 2af8dc9

Please sign in to comment.
You can’t perform that action at this time.