rpmsg_sockif: add rpmsg_socket_ept_release for free conn

Signed-off-by: yintao <yintao@xiaomi.com>
This commit is contained in:
yintao 2023-09-21 18:22:44 +08:00 committed by Xiang Xiao
parent 8ea51b3efc
commit 5b372a4706

View file

@ -121,7 +121,6 @@ struct rpmsg_socket_conn_s
/* server listen-scoket listening: backlog > 0;
* server listen-scoket closed: backlog = -1;
* accept scoket: backlog = -2;
* others: backlog = 0;
*/
@ -454,14 +453,6 @@ static inline void rpmsg_socket_destroy_ept(
if (conn->ept.rdev)
{
if (conn->backlog > 0)
{
/* Listen socket */
conn->backlog = -1;
}
rpmsg_destroy_ept(&conn->ept);
rpmsg_socket_post(&conn->sendsem);
rpmsg_socket_post(&conn->recvsem);
rpmsg_socket_poll_notify(conn, POLLIN | POLLOUT);
@ -469,6 +460,7 @@ static inline void rpmsg_socket_destroy_ept(
nxmutex_unlock(&conn->sendlock);
nxmutex_unlock(&conn->recvlock);
rpmsg_destroy_ept(&conn->ept);
}
static void rpmsg_socket_ns_bound(struct rpmsg_endpoint *ept)
@ -504,6 +496,18 @@ static void rpmsg_socket_ns_unbind(FAR struct rpmsg_endpoint *ept)
nxmutex_unlock(&conn->recvlock);
}
static void rpmsg_socket_ept_release(FAR struct rpmsg_endpoint *ept)
{
FAR struct rpmsg_socket_conn_s *conn = ept->priv;
/* Release conn only when close is called */
if (!conn->crefs)
{
rpmsg_socket_free(conn);
}
}
static void rpmsg_socket_device_created(FAR struct rpmsg_device *rdev,
FAR void *priv)
{
@ -519,6 +523,7 @@ static void rpmsg_socket_device_created(FAR struct rpmsg_device *rdev,
{
conn->ept.priv = conn;
conn->ept.ns_bound_cb = rpmsg_socket_ns_bound;
conn->ept.release_cb = rpmsg_socket_ept_release;
snprintf(buf, sizeof(buf), "%s%s%s", RPMSG_SOCKET_NAME_PREFIX,
conn->rpaddr.rp_name, conn->nameid);
@ -528,17 +533,6 @@ static void rpmsg_socket_device_created(FAR struct rpmsg_device *rdev,
}
}
static void rpmsg_socket_device_destroy(FAR struct rpmsg_device *rdev,
FAR void *priv)
{
FAR struct rpmsg_socket_conn_s *conn = priv;
if (strcmp(conn->rpaddr.rp_cpu, rpmsg_get_cpuname(rdev)) == 0)
{
rpmsg_socket_destroy_ept(conn);
}
}
static bool rpmsg_socket_ns_match(FAR struct rpmsg_device *rdev,
FAR void *priv, FAR const char *name,
uint32_t dest)
@ -588,6 +582,7 @@ static void rpmsg_socket_ns_bind(FAR struct rpmsg_device *rdev,
}
new->ept.priv = new;
new->ept.release_cb = rpmsg_socket_ept_release;
ret = rpmsg_create_ept(&new->ept, rdev, name,
RPMSG_ADDR_ANY, dest,
rpmsg_socket_ept_cb, rpmsg_socket_ns_unbind);
@ -761,7 +756,7 @@ static int rpmsg_socket_connect_internal(FAR struct socket *psock)
ret = rpmsg_register_callback(conn,
rpmsg_socket_device_created,
rpmsg_socket_device_destroy,
NULL,
NULL,
NULL);
if (ret < 0)
@ -785,9 +780,10 @@ static int rpmsg_socket_connect_internal(FAR struct socket *psock)
{
rpmsg_unregister_callback(conn,
rpmsg_socket_device_created,
rpmsg_socket_device_destroy,
NULL,
NULL,
NULL);
rpmsg_socket_destroy_ept(conn);
}
}
else
@ -856,13 +852,6 @@ static int rpmsg_socket_accept(FAR struct socket *psock,
if (conn)
{
conn->backlog = -2;
rpmsg_register_callback(conn,
NULL,
rpmsg_socket_device_destroy,
NULL,
NULL);
if (conn->sendsize == 0)
{
net_sem_wait(&conn->sendsem);
@ -1381,21 +1370,12 @@ static int rpmsg_socket_close(FAR struct socket *psock)
{
FAR struct rpmsg_socket_conn_s *conn = psock->s_conn;
if (conn->crefs > 1)
if (--conn->crefs)
{
conn->crefs--;
return 0;
}
if (conn->backlog == -2)
{
rpmsg_unregister_callback(conn,
NULL,
rpmsg_socket_device_destroy,
NULL,
NULL);
}
else if (conn->backlog)
if (conn->backlog > 0)
{
rpmsg_unregister_callback(conn,
NULL,
@ -1407,13 +1387,20 @@ static int rpmsg_socket_close(FAR struct socket *psock)
{
rpmsg_unregister_callback(conn,
rpmsg_socket_device_created,
rpmsg_socket_device_destroy,
NULL,
NULL,
NULL);
}
rpmsg_socket_destroy_ept(conn);
rpmsg_socket_free(conn);
if (conn->ept.rdev)
{
rpmsg_socket_destroy_ept(conn);
}
else
{
rpmsg_socket_free(conn);
}
return 0;
}