mirror of
https://github.com/apache/nuttx.git
synced 2025-01-13 09:49:21 +08:00
net/local: Add local_freectl to avoid the code duplicaton
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
parent
c7a513b182
commit
61d9394366
1 changed files with 14 additions and 18 deletions
|
@ -58,6 +58,18 @@
|
|||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_LOCAL_SCM
|
||||
static void local_freectl(FAR struct local_conn_s *conn, int count)
|
||||
{
|
||||
FAR struct local_conn_s *peer = conn->lc_peer;
|
||||
|
||||
while (count-- > 0)
|
||||
{
|
||||
file_close(peer->lc_cfps[--peer->lc_cfpcount]);
|
||||
kmm_free(peer->lc_cfps[peer->lc_cfpcount]);
|
||||
peer->lc_cfps[peer->lc_cfpcount] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static int local_sendctl(FAR struct local_conn_s *conn,
|
||||
FAR struct msghdr *msg)
|
||||
{
|
||||
|
@ -71,7 +83,6 @@ static int local_sendctl(FAR struct local_conn_s *conn,
|
|||
int i = 0;
|
||||
|
||||
net_lock();
|
||||
|
||||
peer = conn->lc_peer;
|
||||
if (peer == NULL)
|
||||
{
|
||||
|
@ -124,19 +135,11 @@ static int local_sendctl(FAR struct local_conn_s *conn,
|
|||
}
|
||||
|
||||
net_unlock();
|
||||
|
||||
return count;
|
||||
|
||||
fail:
|
||||
while (i-- > 0)
|
||||
{
|
||||
file_close(peer->lc_cfps[--peer->lc_cfpcount]);
|
||||
kmm_free(peer->lc_cfps[peer->lc_cfpcount]);
|
||||
peer->lc_cfps[peer->lc_cfpcount] = NULL;
|
||||
}
|
||||
|
||||
local_freectl(conn, i);
|
||||
net_unlock();
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif /* CONFIG_NET_LOCAL_SCM */
|
||||
|
@ -423,14 +426,7 @@ ssize_t local_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
|||
if (len < 0 && count > 0)
|
||||
{
|
||||
net_lock();
|
||||
|
||||
while (count-- > 0)
|
||||
{
|
||||
file_close(conn->lc_cfps[--conn->lc_cfpcount]);
|
||||
kmm_free(conn->lc_cfps[conn->lc_cfpcount]);
|
||||
conn->lc_cfps[conn->lc_cfpcount] = NULL;
|
||||
}
|
||||
|
||||
local_freectl(conn, count);
|
||||
net_unlock();
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue