Skip to content

Commit

Permalink
net/local: Add local_freectl to avoid the code duplicaton
Browse files Browse the repository at this point in the history
Signed-off-by: Xiang Xiao <[email protected]>
  • Loading branch information
xiaoxiang781216 committed Feb 28, 2024
1 parent 5471e8e commit f135ba6
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions net/local/local_sendmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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, count);
net_unlock();

return ret;
}
#endif /* CONFIG_NET_LOCAL_SCM */
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f135ba6

Please sign in to comment.