usrsock: add REMOTE_CLOSED event handler to connect

when usrsock client try to connect usrsock server local_loop
socket with an invalid port, server cannot find a listener conn
to handle this connet request, then it will response a TCP_RESET
packet via nuttx existing processing, when before conn recv this
RESET packet, it will trigger usrsock_rpmsg_server poll return
and send REMOTE_CLOSE event to usrsock client.
so usrsock connect_event fucntion need handle this event.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
This commit is contained in:
zhanghongyu 2022-11-21 23:12:08 +08:00 committed by Masayuki Ishikawa
parent 12b3a1ae56
commit ae46cd4fa1

View file

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