diff --git a/net/usrsock/usrsock_connect.c b/net/usrsock/usrsock_connect.c index 7793f6847a..68e8e9e8d7 100644 --- a/net/usrsock/usrsock_connect.c +++ b/net/usrsock/usrsock_connect.c @@ -54,34 +54,30 @@ static uint16_t connect_event(FAR struct net_driver_s *dev, ninfo("socket aborted.\n"); pstate->result = -ECONNABORTED; + } + else if (flags & USRSOCK_EVENT_REMOTE_CLOSED) + { + ninfo("remote closed.\n"); - /* Stop further callbacks */ - - pstate->cb->flags = 0; - pstate->cb->priv = NULL; - pstate->cb->event = NULL; - - /* Wake up the waiting thread */ - - nxsem_post(&pstate->recvsem); + pstate->result = -ECONNREFUSED; } else { ninfo("request completed.\n"); pstate->result = conn->resp.result; - - /* Stop further callbacks */ - - pstate->cb->flags = 0; - pstate->cb->priv = NULL; - pstate->cb->event = NULL; - - /* Wake up the waiting thread */ - - nxsem_post(&pstate->recvsem); } + /* Stop further callbacks */ + + pstate->cb->flags = 0; + pstate->cb->priv = NULL; + pstate->cb->event = NULL; + + /* Wake up the waiting thread */ + + nxsem_post(&pstate->recvsem); + return flags; } @@ -199,6 +195,7 @@ int usrsock_connect(FAR struct socket *psock, ret = usrsock_setup_request_callback(conn, &state, connect_event, USRSOCK_EVENT_ABORT | + USRSOCK_EVENT_REMOTE_CLOSED | USRSOCK_EVENT_REQ_COMPLETE | USRSOCK_EVENT_SENDTO_READY); if (ret < 0)