net/local: set the filep to peer on stream mode

Change-Id: I2e0b8f31bcd3c1c238f1b18456416678d5deae1e
Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
chao.an
2021-09-23 21:56:43 +08:00
committed by anchao
parent 758c042b01
commit f2e15a47de
2 changed files with 26 additions and 14 deletions
+14 -9
View File
@@ -123,7 +123,7 @@ static int psock_fifo_read(FAR struct socket *psock, FAR void *buf,
static void local_recvctl(FAR struct local_conn_s *conn,
FAR struct msghdr *msg)
{
FAR struct local_conn_s *peer = conn->lc_peer;
FAR struct local_conn_s *peer;
struct cmsghdr *cmsg;
int count;
int *fds;
@@ -131,7 +131,16 @@ static void local_recvctl(FAR struct local_conn_s *conn,
net_lock();
if (peer == NULL)
cmsg = CMSG_FIRSTHDR(msg);
count = (cmsg->cmsg_len - sizeof(struct cmsghdr)) / sizeof(int);
cmsg->cmsg_len = 0;
if (count == 0)
{
goto out;
}
if (conn->lc_peer == NULL)
{
peer = local_peerconn(conn);
if (peer == NULL)
@@ -139,16 +148,12 @@ static void local_recvctl(FAR struct local_conn_s *conn,
goto out;
}
}
if (peer->lc_cfpcount == 0)
else
{
goto out;
peer = conn;
}
cmsg = CMSG_FIRSTHDR(msg);
count = (cmsg->cmsg_len - sizeof(struct cmsghdr)) / sizeof(int);
if (count == 0)
if (peer->lc_cfpcount == 0)
{
goto out;
}
+12 -5
View File
@@ -61,6 +61,7 @@
static int local_sendctl(FAR struct local_conn_s *conn,
FAR struct msghdr *msg)
{
FAR struct local_conn_s *peer;
FAR struct file *filep2;
FAR struct file *filep;
struct cmsghdr *cmsg;
@@ -71,6 +72,12 @@ static int local_sendctl(FAR struct local_conn_s *conn,
net_lock();
peer = conn->lc_peer;
if (peer == NULL)
{
peer = conn;
}
for_each_cmsghdr(cmsg, msg)
{
if (!CMSG_OK(msg, cmsg) ||
@@ -84,7 +91,7 @@ static int local_sendctl(FAR struct local_conn_s *conn,
fds = (int *)CMSG_DATA(cmsg);
count = (cmsg->cmsg_len - sizeof(struct cmsghdr)) / sizeof(int);
if (count + conn->lc_cfpcount > LOCAL_NCONTROLFDS)
if (count + peer->lc_cfpcount > LOCAL_NCONTROLFDS)
{
ret = -EMFILE;
goto fail;
@@ -112,7 +119,7 @@ static int local_sendctl(FAR struct local_conn_s *conn,
goto fail;
}
conn->lc_cfps[conn->lc_cfpcount++] = filep2;
peer->lc_cfps[peer->lc_cfpcount++] = filep2;
}
}
@@ -123,9 +130,9 @@ static int local_sendctl(FAR struct local_conn_s *conn,
fail:
while (i-- > 0)
{
file_close(conn->lc_cfps[--conn->lc_cfpcount]);
kmm_free(conn->lc_cfps[conn->lc_cfpcount]);
conn->lc_cfps[conn->lc_cfpcount] = NULL;
file_close(peer->lc_cfps[--peer->lc_cfpcount]);
kmm_free(peer->lc_cfps[peer->lc_cfpcount]);
peer->lc_cfps[peer->lc_cfpcount] = NULL;
}
net_unlock();