net_startmonitor.c always returned zero. In the case where a socket has already been closed, it correctly handled the disconnetion event but still returned OK. Returning OK causes the callers of net_startmonitor to assume that the connection was okay, undoing the good things that net_startmonitor did and causing the socket to be marked as connected. This behavior was noted by Pelle Windestam.

This commit is contained in:
Gregory Nutt
2015-05-28 08:23:51 -06:00
parent 0e2b6929b4
commit 01d176af76
6 changed files with 74 additions and 24 deletions
+15 -7
View File
@@ -81,8 +81,8 @@ struct tcp_connect_s
#ifdef CONFIG_NET_TCP
static inline int psock_setup_callbacks(FAR struct socket *psock,
FAR struct tcp_connect_s *pstate);
static inline void psock_teardown_callbacks(FAR struct tcp_connect_s *pstate,
int status);
static void psock_teardown_callbacks(FAR struct tcp_connect_s *pstate,
int status);
static uint16_t psock_connect_interrupt(FAR struct net_driver_s *dev,
FAR void *pvconn, FAR void *pvpriv,
uint16_t flags);
@@ -124,9 +124,18 @@ static inline int psock_setup_callbacks(FAR struct socket *psock,
/* Set up the connection event monitor */
net_startmonitor(psock);
ret = OK;
ret = net_startmonitor(psock);
if (ret < 0)
{
/* net_startmonitor() can only fail on certain race conditions
* where the connection was lost just before this function was
* called. Undo everything we have done and return a failure.
*/
psock_teardown_callbacks(pstate, ret);
}
}
return ret;
}
#endif /* CONFIG_NET_TCP */
@@ -136,15 +145,14 @@ static inline int psock_setup_callbacks(FAR struct socket *psock,
****************************************************************************/
#ifdef CONFIG_NET_TCP
static inline void psock_teardown_callbacks(FAR struct tcp_connect_s *pstate,
int status)
static void psock_teardown_callbacks(FAR struct tcp_connect_s *pstate,
int status)
{
FAR struct tcp_conn_s *conn = pstate->tc_conn;
/* Make sure that no further interrupts are processed */
tcp_callback_free(conn, pstate->tc_cb);
pstate->tc_cb = NULL;
/* If we successfully connected, we will continue to monitor the connection