net: remove psock reference from connect
Signed-off-by: chao an <anchao@xiaomi.com>
This commit is contained in:
parent
f2a7711ef8
commit
3caa551ff4
7 changed files with 38 additions and 53 deletions
|
@ -56,7 +56,7 @@
|
|||
|
||||
struct can_recvfrom_s
|
||||
{
|
||||
FAR struct socket *pr_sock; /* The parent socket structure */
|
||||
FAR struct can_conn_s *pr_conn; /* Connection associated with the socket */
|
||||
FAR struct devif_callback_s *pr_cb; /* Reference to callback instance */
|
||||
sem_t pr_sem; /* Semaphore signals recv completion */
|
||||
size_t pr_buflen; /* Length of receive buffer */
|
||||
|
@ -175,9 +175,8 @@ static inline void can_newdata(FAR struct net_driver_s *dev,
|
|||
|
||||
if (recvlen < dev->d_len)
|
||||
{
|
||||
FAR struct can_conn_s *conn =
|
||||
(FAR struct can_conn_s *)pstate->pr_sock->s_conn;
|
||||
FAR uint8_t *buffer = (FAR uint8_t *)dev->d_appdata + recvlen;
|
||||
FAR struct can_conn_s *conn = pstate->pr_conn;
|
||||
FAR uint8_t *buffer = dev->d_appdata + recvlen;
|
||||
uint16_t buflen = dev->d_len - recvlen;
|
||||
#ifdef CONFIG_DEBUG_NET
|
||||
uint16_t nsaved;
|
||||
|
@ -230,8 +229,7 @@ static inline void can_newdata(FAR struct net_driver_s *dev,
|
|||
|
||||
static inline int can_readahead(struct can_recvfrom_s *pstate)
|
||||
{
|
||||
FAR struct can_conn_s *conn =
|
||||
(FAR struct can_conn_s *) pstate->pr_sock->s_conn;
|
||||
FAR struct can_conn_s *conn = pstate->pr_conn;
|
||||
FAR struct iob_s *iob;
|
||||
int recvlen;
|
||||
|
||||
|
@ -408,7 +406,7 @@ static uint16_t can_recvfrom_eventhandler(FAR struct net_driver_s *dev,
|
|||
{
|
||||
struct can_recvfrom_s *pstate = pvpriv;
|
||||
#if defined(CONFIG_NET_CANPROTO_OPTIONS) || defined(CONFIG_NET_TIMESTAMP)
|
||||
struct can_conn_s *conn = (struct can_conn_s *)pstate->pr_sock->s_conn;
|
||||
struct can_conn_s *conn = pstate->pr_conn;
|
||||
#endif
|
||||
|
||||
/* 'priv' might be null in some race conditions (?) */
|
||||
|
@ -608,7 +606,7 @@ ssize_t can_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
|||
}
|
||||
#endif
|
||||
|
||||
state.pr_sock = psock;
|
||||
state.pr_conn = conn;
|
||||
|
||||
/* Handle any any CAN data already buffered in a read-ahead buffer. NOTE
|
||||
* that there may be read-ahead data to be retrieved even after the
|
||||
|
|
|
@ -58,7 +58,6 @@
|
|||
|
||||
struct send_s
|
||||
{
|
||||
FAR struct socket *snd_sock; /* Points to the parent socket structure */
|
||||
FAR struct devif_callback_s *snd_cb; /* Reference to callback instance */
|
||||
sem_t snd_sem; /* Used to wake up the waiting thread */
|
||||
FAR const uint8_t *snd_buffer; /* Points to the buffer of data to send */
|
||||
|
@ -218,7 +217,6 @@ ssize_t can_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
|||
memset(&state, 0, sizeof(struct send_s));
|
||||
nxsem_init(&state.snd_sem, 0, 0); /* Doesn't really fail */
|
||||
|
||||
state.snd_sock = psock; /* Socket descriptor */
|
||||
state.snd_buflen = msg->msg_iov->iov_len; /* bytes to send */
|
||||
state.snd_buffer = msg->msg_iov->iov_base; /* Buffer to send from */
|
||||
|
||||
|
|
|
@ -103,7 +103,6 @@ struct rpmsg_socket_conn_s
|
|||
uint32_t recvlen;
|
||||
FAR struct circbuf_s recvbuf;
|
||||
|
||||
FAR struct socket *psock;
|
||||
FAR struct rpmsg_socket_conn_s *next;
|
||||
|
||||
/* server listen-scoket listening: backlog > 0;
|
||||
|
@ -287,11 +286,9 @@ static int rpmsg_socket_ept_cb(FAR struct rpmsg_endpoint *ept,
|
|||
nxmutex_lock(&conn->recvlock);
|
||||
conn->sendsize = head->size;
|
||||
|
||||
if (conn->psock)
|
||||
{
|
||||
conn->sconn.s_flags |= _SF_CONNECTED;
|
||||
_SO_SETERRNO(conn->psock, OK);
|
||||
}
|
||||
|
||||
_SO_CONN_SETERRNO(conn, OK);
|
||||
|
||||
rpmsg_socket_post(&conn->sendsem);
|
||||
rpmsg_socket_poll_notify(conn, POLLOUT);
|
||||
|
@ -589,7 +586,6 @@ static int rpmsg_socket_setup(FAR struct socket *psock, int protocol)
|
|||
}
|
||||
|
||||
psock->s_conn = conn;
|
||||
conn->psock = psock;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -773,7 +769,6 @@ static int rpmsg_socket_accept(FAR struct socket *psock,
|
|||
newsock->s_sockif = psock->s_sockif;
|
||||
newsock->s_type = SOCK_STREAM;
|
||||
newsock->s_conn = conn;
|
||||
conn->psock = newsock;
|
||||
|
||||
rpmsg_socket_getaddr(conn, addr, addrlen);
|
||||
|
||||
|
|
|
@ -45,7 +45,6 @@
|
|||
|
||||
struct accept_s
|
||||
{
|
||||
FAR struct socket *acpt_sock; /* The accepting socket */
|
||||
sem_t acpt_sem; /* Wait for driver event */
|
||||
FAR struct sockaddr *acpt_addr; /* Return connection address */
|
||||
FAR socklen_t *acpt_addrlen; /* Return length of address */
|
||||
|
@ -64,7 +63,7 @@ struct accept_s
|
|||
* Get the sender's address from the UDP packet
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock - The state structure of the accepting socket
|
||||
* listener - The connection structure of the listener
|
||||
* conn - The newly accepted TCP connection
|
||||
* pstate - the recvfrom state structure
|
||||
*
|
||||
|
@ -76,7 +75,7 @@ struct accept_s
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
static inline void accept_tcpsender(FAR struct socket *psock,
|
||||
static inline void accept_tcpsender(FAR struct tcp_conn_s *listener,
|
||||
FAR struct tcp_conn_s *conn,
|
||||
FAR struct sockaddr *addr,
|
||||
socklen_t *addrlen)
|
||||
|
@ -93,7 +92,7 @@ static inline void accept_tcpsender(FAR struct socket *psock,
|
|||
* select which one to use when obtaining the sender's IP address.
|
||||
*/
|
||||
|
||||
if (psock->s_domain == PF_INET)
|
||||
if (listener->domain == PF_INET)
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
{
|
||||
FAR struct sockaddr_in *inaddr = (FAR struct sockaddr_in *)addr;
|
||||
|
@ -116,7 +115,9 @@ static inline void accept_tcpsender(FAR struct socket *psock,
|
|||
{
|
||||
FAR struct sockaddr_in6 *inaddr = (FAR struct sockaddr_in6 *)addr;
|
||||
|
||||
DEBUGASSERT(psock->s_domain == PF_INET6);
|
||||
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
|
||||
DEBUGASSERT(listener->domain == PF_INET6);
|
||||
#endif
|
||||
inaddr->sin6_family = AF_INET6;
|
||||
inaddr->sin6_port = conn->rport;
|
||||
net_ipv6addr_copy(inaddr->sin6_addr.s6_addr, conn->u.ipv6.raddr);
|
||||
|
@ -155,7 +156,7 @@ static int accept_eventhandler(FAR struct tcp_conn_s *listener,
|
|||
{
|
||||
/* Get the connection address */
|
||||
|
||||
accept_tcpsender(pstate->acpt_sock, conn, pstate->acpt_addr,
|
||||
accept_tcpsender(listener, conn, pstate->acpt_addr,
|
||||
pstate->acpt_addrlen);
|
||||
|
||||
/* Save the connection structure */
|
||||
|
@ -231,7 +232,7 @@ int psock_tcp_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
|
|||
/* Yes... get the address of the connected client */
|
||||
|
||||
ninfo("Pending conn=%p\n", state.acpt_newconn);
|
||||
accept_tcpsender(psock, state.acpt_newconn, addr, addrlen);
|
||||
accept_tcpsender(conn, state.acpt_newconn, addr, addrlen);
|
||||
}
|
||||
|
||||
/* In general, this implementation will not support non-blocking socket
|
||||
|
@ -254,7 +255,6 @@ int psock_tcp_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
|
|||
* ready.
|
||||
*/
|
||||
|
||||
state.acpt_sock = psock;
|
||||
state.acpt_addr = addr;
|
||||
state.acpt_addrlen = addrlen;
|
||||
state.acpt_newconn = NULL;
|
||||
|
|
|
@ -77,7 +77,7 @@
|
|||
|
||||
struct send_s
|
||||
{
|
||||
FAR struct socket *snd_sock; /* Points to the parent socket structure */
|
||||
FAR struct tcp_conn_s *snd_conn; /* The TCP connection of interest */
|
||||
FAR struct devif_callback_s *snd_cb; /* Reference to callback instance */
|
||||
sem_t snd_sem; /* Used to wake up the waiting thread */
|
||||
FAR const uint8_t *snd_buffer; /* Points to the buffer of data to send */
|
||||
|
@ -169,19 +169,15 @@ static uint16_t tcpsend_eventhandler(FAR struct net_driver_s *dev,
|
|||
FAR void *pvpriv, uint16_t flags)
|
||||
{
|
||||
FAR struct send_s *pstate = pvpriv;
|
||||
FAR struct socket *psock;
|
||||
FAR struct tcp_conn_s *conn;
|
||||
|
||||
DEBUGASSERT(pstate != NULL);
|
||||
|
||||
psock = pstate->snd_sock;
|
||||
DEBUGASSERT(psock != NULL);
|
||||
|
||||
/* Get the TCP connection pointer reliably from
|
||||
* the corresponding TCP socket.
|
||||
*/
|
||||
|
||||
conn = psock->s_conn;
|
||||
conn = pstate->snd_conn;
|
||||
DEBUGASSERT(conn != NULL);
|
||||
|
||||
/* The TCP socket is connected and, hence, should be bound to a device.
|
||||
|
@ -604,7 +600,7 @@ ssize_t psock_tcp_send(FAR struct socket *psock,
|
|||
memset(&state, 0, sizeof(struct send_s));
|
||||
nxsem_init(&state.snd_sem, 0, 0); /* Doesn't really fail */
|
||||
|
||||
state.snd_sock = psock; /* Socket descriptor to use */
|
||||
state.snd_conn = conn; /* Socket descriptor to use */
|
||||
state.snd_buflen = len; /* Number of bytes to send */
|
||||
state.snd_buffer = buf; /* Buffer to send from */
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@
|
|||
|
||||
struct sendfile_s
|
||||
{
|
||||
FAR struct socket *snd_sock; /* Points to the parent socket structure */
|
||||
FAR struct tcp_conn_s *snd_conn; /* Connection associated with the socket */
|
||||
FAR struct devif_callback_s *snd_cb; /* Reference to callback instance */
|
||||
FAR struct file *snd_file; /* File structure of the input file */
|
||||
sem_t snd_sem; /* Used to wake up the waiting thread */
|
||||
|
@ -118,20 +118,16 @@ static uint16_t sendfile_eventhandler(FAR struct net_driver_s *dev,
|
|||
FAR void *pvpriv, uint16_t flags)
|
||||
{
|
||||
FAR struct sendfile_s *pstate = pvpriv;
|
||||
FAR struct socket *psock;
|
||||
FAR struct tcp_conn_s *conn;
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(pstate != NULL);
|
||||
|
||||
psock = pstate->snd_sock;
|
||||
DEBUGASSERT(psock != NULL);
|
||||
|
||||
/* Get the TCP connection pointer reliably from
|
||||
* the corresponding TCP socket.
|
||||
*/
|
||||
|
||||
conn = psock->s_conn;
|
||||
conn = pstate->snd_conn;
|
||||
DEBUGASSERT(conn != NULL);
|
||||
|
||||
/* The TCP socket is connected and, hence, should be bound to a device.
|
||||
|
@ -174,7 +170,7 @@ static uint16_t sendfile_eventhandler(FAR struct net_driver_s *dev,
|
|||
if (IFF_IS_IPv6(dev->d_flags))
|
||||
#endif
|
||||
{
|
||||
DEBUGASSERT(pstate->snd_sock->s_domain == PF_INET6);
|
||||
DEBUGASSERT(conn->domain == PF_INET6);
|
||||
tcp = TCPIPv6BUF;
|
||||
}
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
@ -184,7 +180,9 @@ static uint16_t sendfile_eventhandler(FAR struct net_driver_s *dev,
|
|||
else
|
||||
#endif
|
||||
{
|
||||
DEBUGASSERT(pstate->snd_sock->s_domain == PF_INET);
|
||||
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
|
||||
DEBUGASSERT(conn->domain == PF_INET);
|
||||
#endif
|
||||
tcp = TCPIPv4BUF;
|
||||
}
|
||||
#endif /* CONFIG_NET_IPv4 */
|
||||
|
@ -503,7 +501,7 @@ ssize_t tcp_sendfile(FAR struct socket *psock, FAR struct file *infile,
|
|||
memset(&state, 0, sizeof(struct sendfile_s));
|
||||
nxsem_init(&state.snd_sem, 0, 0); /* Doesn't really fail */
|
||||
|
||||
state.snd_sock = psock; /* Socket descriptor to use */
|
||||
state.snd_conn = conn; /* Tcp conn to use */
|
||||
state.snd_foffset = offset ? *offset : startpos; /* Input file offset */
|
||||
state.snd_flen = count; /* Number of bytes to send */
|
||||
state.snd_file = infile; /* File to read from */
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
struct sendto_s
|
||||
{
|
||||
#ifdef NEED_IPDOMAIN_SUPPORT
|
||||
FAR struct socket *st_sock; /* Points to the parent socket structure */
|
||||
FAR struct udp_conn_s *st_conn; /* The UDP connection of interest */
|
||||
#endif
|
||||
FAR struct devif_callback_s *st_cb; /* Reference to callback instance */
|
||||
FAR struct net_driver_s *st_dev; /* Driver that will perform the transmission */
|
||||
|
@ -102,12 +102,12 @@ struct sendto_s
|
|||
static inline void sendto_ipselect(FAR struct net_driver_s *dev,
|
||||
FAR struct sendto_s *pstate)
|
||||
{
|
||||
FAR struct socket *psock = pstate->st_sock;
|
||||
DEBUGASSERT(psock);
|
||||
FAR struct udp_conn_s *conn = pstate->st_conn;
|
||||
DEBUGASSERT(conn);
|
||||
|
||||
/* Which domain the socket support */
|
||||
|
||||
if (psock->s_domain == PF_INET)
|
||||
if (conn->domain == PF_INET)
|
||||
{
|
||||
/* Select the IPv4 domain */
|
||||
|
||||
|
@ -117,7 +117,7 @@ static inline void sendto_ipselect(FAR struct net_driver_s *dev,
|
|||
{
|
||||
/* Select the IPv6 domain */
|
||||
|
||||
DEBUGASSERT(psock->s_domain == PF_INET6);
|
||||
DEBUGASSERT(conn->domain == PF_INET6);
|
||||
udp_ipv6_select(dev);
|
||||
}
|
||||
}
|
||||
|
@ -402,11 +402,11 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf,
|
|||
state.st_buffer = buf;
|
||||
|
||||
#ifdef NEED_IPDOMAIN_SUPPORT
|
||||
/* Save the reference to the socket structure if it will be needed for
|
||||
/* Save the reference to the conn structure if it will be needed for
|
||||
* asynchronous processing.
|
||||
*/
|
||||
|
||||
state.st_sock = psock;
|
||||
state.st_conn = conn;
|
||||
#endif
|
||||
|
||||
/* Check if the socket is connected */
|
||||
|
|
Loading…
Reference in a new issue