mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 00:14:22 +08:00
local_sendto:move lc_sendlock position to protect file system interface
Signed-off-by: wangchen <wangchen41@xiaomi.com>
This commit is contained in:
committed by
Alan Carvalho de Assis
parent
622302fe02
commit
eb0055fd4a
+31
-24
@@ -273,6 +273,17 @@ static ssize_t local_sendto(FAR struct socket *psock,
|
|||||||
return -EAFNOSUPPORT;
|
return -EAFNOSUPPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* At present, only standard pathname type address are support */
|
||||||
|
|
||||||
|
if (tolen < sizeof(sa_family_t) + 2)
|
||||||
|
{
|
||||||
|
/* EFAULT
|
||||||
|
* - An invalid user space address was specified for a parameter
|
||||||
|
*/
|
||||||
|
|
||||||
|
return -EFAULT;
|
||||||
|
}
|
||||||
|
|
||||||
/* If this is a connected socket, then return EISCONN */
|
/* If this is a connected socket, then return EISCONN */
|
||||||
|
|
||||||
if (psock->s_type != SOCK_DGRAM)
|
if (psock->s_type != SOCK_DGRAM)
|
||||||
@@ -301,21 +312,21 @@ static ssize_t local_sendto(FAR struct socket *psock,
|
|||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Make sure that dgram is sent safely */
|
||||||
|
|
||||||
|
ret = nxmutex_lock(&conn->lc_sendlock);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
/* May fail because the task was canceled. */
|
||||||
|
|
||||||
|
nerr("ERROR: Failed to get localsocket sendlock: %zd\n", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/* The outgoing FIFO should not be open */
|
/* The outgoing FIFO should not be open */
|
||||||
|
|
||||||
DEBUGASSERT(conn->lc_outfile.f_inode == NULL);
|
DEBUGASSERT(conn->lc_outfile.f_inode == NULL);
|
||||||
|
|
||||||
/* At present, only standard pathname type address are support */
|
|
||||||
|
|
||||||
if (tolen < sizeof(sa_family_t) + 2)
|
|
||||||
{
|
|
||||||
/* EFAULT
|
|
||||||
* - An invalid user space address was specified for a parameter
|
|
||||||
*/
|
|
||||||
|
|
||||||
return -EFAULT;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Make sure that half duplex FIFO has been created.
|
/* Make sure that half duplex FIFO has been created.
|
||||||
* REVISIT: Or should be just make sure that it already exists?
|
* REVISIT: Or should be just make sure that it already exists?
|
||||||
*/
|
*/
|
||||||
@@ -325,7 +336,7 @@ static ssize_t local_sendto(FAR struct socket *psock,
|
|||||||
{
|
{
|
||||||
nerr("ERROR: Failed to create FIFO for %s: %zd\n",
|
nerr("ERROR: Failed to create FIFO for %s: %zd\n",
|
||||||
unaddr->sun_path, ret);
|
unaddr->sun_path, ret);
|
||||||
return ret;
|
goto errout_with_lock;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Open the sending side of the transfer */
|
/* Open the sending side of the transfer */
|
||||||
@@ -341,22 +352,13 @@ static ssize_t local_sendto(FAR struct socket *psock,
|
|||||||
goto errout_with_halfduplex;
|
goto errout_with_halfduplex;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make sure that dgram is sent safely */
|
|
||||||
|
|
||||||
ret = nxmutex_lock(&conn->lc_sendlock);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
/* May fail because the task was canceled. */
|
|
||||||
|
|
||||||
goto errout_with_sender;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Send the preamble */
|
/* Send the preamble */
|
||||||
|
|
||||||
ret = local_send_preamble(conn, &conn->lc_outfile, buf, len);
|
ret = local_send_preamble(conn, &conn->lc_outfile, buf, len);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
nerr("ERROR: Failed to send the preamble: %zd\n", ret);
|
nerr("ERROR: Failed to send the preamble: %zd\n", ret);
|
||||||
|
goto errout_with_sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send the packet */
|
/* Send the packet */
|
||||||
@@ -365,10 +367,9 @@ static ssize_t local_sendto(FAR struct socket *psock,
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
nerr("ERROR: Failed to send the packet: %zd\n", ret);
|
nerr("ERROR: Failed to send the packet: %zd\n", ret);
|
||||||
|
goto errout_with_sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
nxmutex_unlock(&conn->lc_sendlock);
|
|
||||||
|
|
||||||
errout_with_sender:
|
errout_with_sender:
|
||||||
|
|
||||||
/* Now we can close the write-only socket descriptor */
|
/* Now we can close the write-only socket descriptor */
|
||||||
@@ -381,6 +382,12 @@ errout_with_halfduplex:
|
|||||||
/* Release our reference to the half duplex FIFO */
|
/* Release our reference to the half duplex FIFO */
|
||||||
|
|
||||||
local_release_halfduplex(conn);
|
local_release_halfduplex(conn);
|
||||||
|
|
||||||
|
errout_with_lock:
|
||||||
|
|
||||||
|
/* Release localsocket sendlock */
|
||||||
|
|
||||||
|
nxmutex_unlock(&conn->lc_sendlock);
|
||||||
return ret;
|
return ret;
|
||||||
#else
|
#else
|
||||||
return -EISCONN;
|
return -EISCONN;
|
||||||
|
|||||||
Reference in New Issue
Block a user