Move _SF_BOUND and _SF_CONNECTED modification to common place

This commit is contained in:
Xiang Xiao 2020-01-31 17:34:28 +08:00 committed by Gregory Nutt
parent 709dc19350
commit 6e6c670190
10 changed files with 19 additions and 49 deletions

View File

@ -271,7 +271,7 @@ static int bluetooth_connect(FAR struct socket *psock,
{
FAR struct bluetooth_conn_s *conn;
FAR struct sockaddr_bt_s *btaddr;
int ret;
int ret = OK;
DEBUGASSERT(psock != NULL || addr != NULL);
conn = (FAR struct bluetooth_conn_s *)psock->s_conn;
@ -286,11 +286,6 @@ static int bluetooth_connect(FAR struct socket *psock,
btaddr = (FAR struct sockaddr_bt_s *)addr;
memcpy(&conn->bc_raddr, &btaddr->bt_bdaddr, sizeof(bt_addr_t));
conn->bc_channel = btaddr->bt_channel;
/* Mark the socket as connected. */
psock->s_flags |= _SF_CONNECTED;
ret = OK;
}
else
{
@ -437,9 +432,6 @@ static int bluetooth_bind(FAR struct socket *psock,
memcpy(&conn->bc_laddr, &iaddr->bt_bdaddr, sizeof(bt_addr_t));
/* Mark the socket bound */
psock->s_flags |= _SF_BOUND;
return OK;
}

View File

@ -275,7 +275,7 @@ static int ieee802154_connect(FAR struct socket *psock,
{
FAR struct ieee802154_conn_s *conn;
FAR struct sockaddr_ieee802154_s *ieeeaddr;
int ret;
int ret = OK;
DEBUGASSERT(psock != NULL || addr != NULL);
conn = (FAR struct ieee802154_conn_s *)psock->s_conn;
@ -290,11 +290,6 @@ static int ieee802154_connect(FAR struct socket *psock,
ieeeaddr = (FAR struct sockaddr_ieee802154_s *)addr;
memcpy(&conn->raddr, &ieeeaddr->sa_addr,
sizeof(struct ieee802154_saddr_s));
/* Mark the socket as connected. */
psock->s_flags |= _SF_CONNECTED;
ret = OK;
}
else
{
@ -444,9 +439,6 @@ static int ieee802154_bind(FAR struct socket *psock,
memcpy(&conn->laddr, &iaddr->sa_addr, sizeof(struct ieee802154_saddr_s));
/* Mark the socket bound */
psock->s_flags |= _SF_BOUND;
return OK;
}

View File

@ -409,13 +409,6 @@ static int inet_bind(FAR struct socket *psock,
/* Bind a TCP/IP stream socket. */
ret = tcp_bind(psock->s_conn, addr);
/* Mark the socket bound */
if (ret >= 0)
{
psock->s_flags |= _SF_BOUND;
}
#else
nwarn("WARNING: TCP/IP stack is not available in this configuration\n");
return -ENOSYS;
@ -431,13 +424,6 @@ static int inet_bind(FAR struct socket *psock,
/* Bind a UDP/IP datagram socket */
ret = udp_bind(psock->s_conn, addr);
/* Mark the socket bound */
if (ret >= 0)
{
psock->s_flags |= _SF_BOUND;
}
#else
nwarn("WARNING: UDP stack is not available in this configuration\n");
ret = -ENOSYS;
@ -757,15 +743,13 @@ static int inet_connect(FAR struct socket *psock,
{
/* Failed to connect or explicitly disconnected */
psock->s_flags &= ~_SF_CONNECTED;
conn->flags &= ~_UDP_FLAG_CONNECTMODE;
conn->flags &= ~_UDP_FLAG_CONNECTMODE;
}
else
{
/* Successfully connected */
psock->s_flags |= _SF_CONNECTED;
conn->flags |= _UDP_FLAG_CONNECTMODE;
conn->flags |= _UDP_FLAG_CONNECTMODE;
}
return ret;

View File

@ -102,7 +102,7 @@ int ipv4_getpeername(FAR struct socket *psock, FAR struct sockaddr *addr,
/* Verify that the socket has been connected */
if ((psock->s_flags & _SF_CONNECTED) == 0)
if (_SS_ISCONNECTED(psock->s_flags) == 0)
{
return -ENOTCONN;
}

View File

@ -101,7 +101,7 @@ int ipv6_getpeername(FAR struct socket *psock, FAR struct sockaddr *addr,
/* Verify that the socket has been connected */
if ((psock->s_flags & _SF_CONNECTED) == 0)
if (_SS_ISCONNECTED(psock->s_flags) == 0)
{
return -ENOTCONN;
}

View File

@ -309,13 +309,6 @@ static int local_bind(FAR struct socket *psock,
/* Bind the Unix domain connection structure */
ret = psock_local_bind(psock, addr, addrlen);
/* Mark the socket bound */
if (ret >= 0)
{
psock->s_flags |= _SF_BOUND;
}
}
break;
#endif /* CONFIG_NET_LOCAL_STREAM || CONFIG_NET_LOCAL_DGRAM */

View File

@ -287,7 +287,6 @@ static int netlink_bind(FAR struct socket *psock,
conn->pid = nladdr->nl_pid;
conn->groups = nladdr->nl_groups;
psock->s_flags |= _SF_BOUND;
return OK;
}

View File

@ -387,9 +387,6 @@ static int pkt_bind(FAR struct socket *psock, FAR const struct sockaddr *addr,
conn->ifindex = ifindex;
memcpy(conn->lmac, dev->d_mac.ether.ether_addr_octet, 6);
/* Mark the socket bound */
psock->s_flags |= _SF_BOUND;
return OK;
}
else

View File

@ -112,6 +112,10 @@ int psock_bind(FAR struct socket *psock, const struct sockaddr *addr,
return ret;
}
/* Mark the socket bound */
psock->s_flags |= _SF_BOUND;
return OK;
}

View File

@ -156,6 +156,15 @@ int psock_connect(FAR struct socket *psock, FAR const struct sockaddr *addr,
return ret;
}
if (addr != NULL)
{
psock->s_flags |= _SF_CONNECTED;
}
else
{
psock->s_flags &= ~_SF_CONNECTED;
}
return OK;
}