diff --git a/net/netdev/netdev_ioctl.c b/net/netdev/netdev_ioctl.c index 903b261108c..dfeba237488 100644 --- a/net/netdev/netdev_ioctl.c +++ b/net/netdev/netdev_ioctl.c @@ -588,7 +588,7 @@ static int netdev_ifrioctl(FAR struct socket *psock, int cmd, dev = netdev_ifrdev(req); if (dev) { - if (req->ifr_flags & IFF_UP) + if ((req->ifr_flags & IFF_UP) != 0) { /* Yes.. bring the interface up */ @@ -597,7 +597,7 @@ static int netdev_ifrioctl(FAR struct socket *psock, int cmd, /* Is this a request to take the interface down? */ - else if (req->ifr_flags & IFF_DOWN) + else if ((req->ifr_flags & IFF_DOWN) != 0) { /* Yes.. take the interface down */ diff --git a/net/socket/connect.c b/net/socket/connect.c index 9d5d9699ef1..704c18d3226 100644 --- a/net/socket/connect.c +++ b/net/socket/connect.c @@ -121,19 +121,7 @@ static inline int psock_setup_callbacks(FAR struct socket *psock, TCP_TIMEDOUT | TCP_CONNECTED | NETDEV_DOWN); pstate->tc_cb->priv = (void*)pstate; pstate->tc_cb->event = psock_connect_interrupt; - - /* Set up the connection event monitor */ - - 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); - } + ret = OK; } return ret; @@ -390,11 +378,29 @@ static inline int psock_tcp_connect(FAR struct socket *psock, psock_teardown_callbacks(&state, ret); } - /* Mark the connection bound and connected */ + /* Check if the socket was successffully connected. */ if (ret >= 0) { - psock->s_flags |= (_SF_BOUND|_SF_CONNECTED); + /* Yes.. Mark the connection bound and connected */ + + psock->s_flags |= (_SF_BOUND | _SF_CONNECTED); + + /* Now that we are connected, we need to set up to monitor the + * state of the connection up the connection event monitor. + */ + + 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. That is not expected to + * happen in this context, but just in case... + */ + + net_lostconnection(psock, TCP_ABORT); + } } }