1
0
Fork 0
forked from nuttx/nuttx-update

Ensure psock_socket and psock_accept initialize s_crefs to 1

This simplifies the caller usage
This commit is contained in:
Xiang Xiao 2020-01-31 17:27:46 +08:00 committed by Gregory Nutt
parent 9f9566c0eb
commit 0b860726db
7 changed files with 4 additions and 14 deletions

View file

@ -489,7 +489,6 @@ static int net_rpmsg_drv_sockioctl_task(int argc, FAR char *argv[])
protocol = IPPROTO_ICMP6;
}
sock.s_crefs = 1; /* Initialize reference count manually */
msg->header.result = psock_socket(domain, type, protocol, &sock);
if (msg->header.result >= 0)
{

View file

@ -408,8 +408,7 @@ int rpcclnt_connect(struct rpcclnt *rpc)
return errval;
}
so->s_crefs = 1;
rpc->rc_so = so;
rpc->rc_so = so;
/* Always set receive timeout to detect server crash and reconnect.
* Otherwise, we can get stuck in psock_receive forever.

View file

@ -1370,8 +1370,6 @@ static int userfs_bind(FAR struct inode *blkdriver, FAR const void *data,
goto errout_with_alloc;
}
priv->psock.s_crefs = 1;
/* Bind the socket to the client address */
client.sin_family = AF_INET;
@ -1386,8 +1384,6 @@ static int userfs_bind(FAR struct inode *blkdriver, FAR const void *data,
goto errout_with_psock;
}
priv->psock.s_crefs = 1;
/* Mounted! */
*handle = (FAR void *)priv;

View file

@ -119,9 +119,7 @@ static void vnc_reset_session(FAR struct vnc_session_s *session,
/* [Re-]initialize the session. */
memset(&session->connect, 0, sizeof(struct socket));
session->connect.s_crefs = 1;
memset(&session->listen, 0, sizeof(struct socket));
session->listen.s_crefs = 1;
/* Put all of the pre-allocated update structures into the freelist */

View file

@ -879,6 +879,7 @@ static int inet_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
/* Initialize the socket structure. */
newsock->s_crefs = 1;
newsock->s_domain = psock->s_domain;
newsock->s_type = SOCK_STREAM;
newsock->s_sockif = psock->s_sockif;

View file

@ -234,6 +234,7 @@ int local_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
{
/* Setup the client socket structure */
newsock->s_crefs = 1;
newsock->s_domain = psock->s_domain;
newsock->s_type = SOCK_STREAM;
newsock->s_sockif = psock->s_sockif;

View file

@ -60,11 +60,6 @@
* socket() creates an endpoint for communication and returns a socket
* structure.
*
* NOTE: This function does not set the reference count on the socket
* structure. This down by the socket() front end when socket structure
* was allocated. Internal OS users of psock_socket() must set the s_crefs
* field to one if psock_socket() returns success.
*
* Input Parameters:
* domain (see sys/socket.h)
* type (see sys/socket.h)
@ -102,6 +97,7 @@ int psock_socket(int domain, int type, int protocol, FAR struct socket *psock)
/* Initialize the socket structure */
psock->s_crefs = 1;
psock->s_domain = domain;
psock->s_type = type;
psock->s_conn = NULL;