Move _SF_BOUND and _SF_CONNECTED modification to common place
This commit is contained in:
parent
709dc19350
commit
6e6c670190
@ -271,7 +271,7 @@ static int bluetooth_connect(FAR struct socket *psock,
|
|||||||
{
|
{
|
||||||
FAR struct bluetooth_conn_s *conn;
|
FAR struct bluetooth_conn_s *conn;
|
||||||
FAR struct sockaddr_bt_s *btaddr;
|
FAR struct sockaddr_bt_s *btaddr;
|
||||||
int ret;
|
int ret = OK;
|
||||||
|
|
||||||
DEBUGASSERT(psock != NULL || addr != NULL);
|
DEBUGASSERT(psock != NULL || addr != NULL);
|
||||||
conn = (FAR struct bluetooth_conn_s *)psock->s_conn;
|
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;
|
btaddr = (FAR struct sockaddr_bt_s *)addr;
|
||||||
memcpy(&conn->bc_raddr, &btaddr->bt_bdaddr, sizeof(bt_addr_t));
|
memcpy(&conn->bc_raddr, &btaddr->bt_bdaddr, sizeof(bt_addr_t));
|
||||||
conn->bc_channel = btaddr->bt_channel;
|
conn->bc_channel = btaddr->bt_channel;
|
||||||
|
|
||||||
/* Mark the socket as connected. */
|
|
||||||
|
|
||||||
psock->s_flags |= _SF_CONNECTED;
|
|
||||||
ret = OK;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -437,9 +432,6 @@ static int bluetooth_bind(FAR struct socket *psock,
|
|||||||
|
|
||||||
memcpy(&conn->bc_laddr, &iaddr->bt_bdaddr, sizeof(bt_addr_t));
|
memcpy(&conn->bc_laddr, &iaddr->bt_bdaddr, sizeof(bt_addr_t));
|
||||||
|
|
||||||
/* Mark the socket bound */
|
|
||||||
|
|
||||||
psock->s_flags |= _SF_BOUND;
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,7 +275,7 @@ static int ieee802154_connect(FAR struct socket *psock,
|
|||||||
{
|
{
|
||||||
FAR struct ieee802154_conn_s *conn;
|
FAR struct ieee802154_conn_s *conn;
|
||||||
FAR struct sockaddr_ieee802154_s *ieeeaddr;
|
FAR struct sockaddr_ieee802154_s *ieeeaddr;
|
||||||
int ret;
|
int ret = OK;
|
||||||
|
|
||||||
DEBUGASSERT(psock != NULL || addr != NULL);
|
DEBUGASSERT(psock != NULL || addr != NULL);
|
||||||
conn = (FAR struct ieee802154_conn_s *)psock->s_conn;
|
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;
|
ieeeaddr = (FAR struct sockaddr_ieee802154_s *)addr;
|
||||||
memcpy(&conn->raddr, &ieeeaddr->sa_addr,
|
memcpy(&conn->raddr, &ieeeaddr->sa_addr,
|
||||||
sizeof(struct ieee802154_saddr_s));
|
sizeof(struct ieee802154_saddr_s));
|
||||||
|
|
||||||
/* Mark the socket as connected. */
|
|
||||||
|
|
||||||
psock->s_flags |= _SF_CONNECTED;
|
|
||||||
ret = OK;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -444,9 +439,6 @@ static int ieee802154_bind(FAR struct socket *psock,
|
|||||||
|
|
||||||
memcpy(&conn->laddr, &iaddr->sa_addr, sizeof(struct ieee802154_saddr_s));
|
memcpy(&conn->laddr, &iaddr->sa_addr, sizeof(struct ieee802154_saddr_s));
|
||||||
|
|
||||||
/* Mark the socket bound */
|
|
||||||
|
|
||||||
psock->s_flags |= _SF_BOUND;
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -409,13 +409,6 @@ static int inet_bind(FAR struct socket *psock,
|
|||||||
/* Bind a TCP/IP stream socket. */
|
/* Bind a TCP/IP stream socket. */
|
||||||
|
|
||||||
ret = tcp_bind(psock->s_conn, addr);
|
ret = tcp_bind(psock->s_conn, addr);
|
||||||
|
|
||||||
/* Mark the socket bound */
|
|
||||||
|
|
||||||
if (ret >= 0)
|
|
||||||
{
|
|
||||||
psock->s_flags |= _SF_BOUND;
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
nwarn("WARNING: TCP/IP stack is not available in this configuration\n");
|
nwarn("WARNING: TCP/IP stack is not available in this configuration\n");
|
||||||
return -ENOSYS;
|
return -ENOSYS;
|
||||||
@ -431,13 +424,6 @@ static int inet_bind(FAR struct socket *psock,
|
|||||||
/* Bind a UDP/IP datagram socket */
|
/* Bind a UDP/IP datagram socket */
|
||||||
|
|
||||||
ret = udp_bind(psock->s_conn, addr);
|
ret = udp_bind(psock->s_conn, addr);
|
||||||
|
|
||||||
/* Mark the socket bound */
|
|
||||||
|
|
||||||
if (ret >= 0)
|
|
||||||
{
|
|
||||||
psock->s_flags |= _SF_BOUND;
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
nwarn("WARNING: UDP stack is not available in this configuration\n");
|
nwarn("WARNING: UDP stack is not available in this configuration\n");
|
||||||
ret = -ENOSYS;
|
ret = -ENOSYS;
|
||||||
@ -757,14 +743,12 @@ static int inet_connect(FAR struct socket *psock,
|
|||||||
{
|
{
|
||||||
/* Failed to connect or explicitly disconnected */
|
/* Failed to connect or explicitly disconnected */
|
||||||
|
|
||||||
psock->s_flags &= ~_SF_CONNECTED;
|
|
||||||
conn->flags &= ~_UDP_FLAG_CONNECTMODE;
|
conn->flags &= ~_UDP_FLAG_CONNECTMODE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Successfully connected */
|
/* Successfully connected */
|
||||||
|
|
||||||
psock->s_flags |= _SF_CONNECTED;
|
|
||||||
conn->flags |= _UDP_FLAG_CONNECTMODE;
|
conn->flags |= _UDP_FLAG_CONNECTMODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ int ipv4_getpeername(FAR struct socket *psock, FAR struct sockaddr *addr,
|
|||||||
|
|
||||||
/* Verify that the socket has been connected */
|
/* Verify that the socket has been connected */
|
||||||
|
|
||||||
if ((psock->s_flags & _SF_CONNECTED) == 0)
|
if (_SS_ISCONNECTED(psock->s_flags) == 0)
|
||||||
{
|
{
|
||||||
return -ENOTCONN;
|
return -ENOTCONN;
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ int ipv6_getpeername(FAR struct socket *psock, FAR struct sockaddr *addr,
|
|||||||
|
|
||||||
/* Verify that the socket has been connected */
|
/* Verify that the socket has been connected */
|
||||||
|
|
||||||
if ((psock->s_flags & _SF_CONNECTED) == 0)
|
if (_SS_ISCONNECTED(psock->s_flags) == 0)
|
||||||
{
|
{
|
||||||
return -ENOTCONN;
|
return -ENOTCONN;
|
||||||
}
|
}
|
||||||
|
@ -309,13 +309,6 @@ static int local_bind(FAR struct socket *psock,
|
|||||||
/* Bind the Unix domain connection structure */
|
/* Bind the Unix domain connection structure */
|
||||||
|
|
||||||
ret = psock_local_bind(psock, addr, addrlen);
|
ret = psock_local_bind(psock, addr, addrlen);
|
||||||
|
|
||||||
/* Mark the socket bound */
|
|
||||||
|
|
||||||
if (ret >= 0)
|
|
||||||
{
|
|
||||||
psock->s_flags |= _SF_BOUND;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif /* CONFIG_NET_LOCAL_STREAM || CONFIG_NET_LOCAL_DGRAM */
|
#endif /* CONFIG_NET_LOCAL_STREAM || CONFIG_NET_LOCAL_DGRAM */
|
||||||
|
@ -287,7 +287,6 @@ static int netlink_bind(FAR struct socket *psock,
|
|||||||
conn->pid = nladdr->nl_pid;
|
conn->pid = nladdr->nl_pid;
|
||||||
conn->groups = nladdr->nl_groups;
|
conn->groups = nladdr->nl_groups;
|
||||||
|
|
||||||
psock->s_flags |= _SF_BOUND;
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -387,9 +387,6 @@ static int pkt_bind(FAR struct socket *psock, FAR const struct sockaddr *addr,
|
|||||||
conn->ifindex = ifindex;
|
conn->ifindex = ifindex;
|
||||||
memcpy(conn->lmac, dev->d_mac.ether.ether_addr_octet, 6);
|
memcpy(conn->lmac, dev->d_mac.ether.ether_addr_octet, 6);
|
||||||
|
|
||||||
/* Mark the socket bound */
|
|
||||||
|
|
||||||
psock->s_flags |= _SF_BOUND;
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -112,6 +112,10 @@ int psock_bind(FAR struct socket *psock, const struct sockaddr *addr,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Mark the socket bound */
|
||||||
|
|
||||||
|
psock->s_flags |= _SF_BOUND;
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,6 +156,15 @@ int psock_connect(FAR struct socket *psock, FAR const struct sockaddr *addr,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (addr != NULL)
|
||||||
|
{
|
||||||
|
psock->s_flags |= _SF_CONNECTED;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
psock->s_flags &= ~_SF_CONNECTED;
|
||||||
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user