mirror of
https://github.com/apache/nuttx.git
synced 2026-05-31 23:40:19 +08:00
Attempt to fix race condition reported in issue #3647
This commit is contained in:
committed by
Xiang Xiao
parent
38eadbb575
commit
a885b24cc1
@@ -538,9 +538,12 @@ ssize_t psock_tcp_send(FAR struct socket *psock,
|
|||||||
goto errout;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If this is an un-connected socket, then return ENOTCONN */
|
/* Check early if this is an un-connected socket, if so, then
|
||||||
|
* return -ENOTCONN. Note, we will have to check this again, as we can't
|
||||||
|
* guarantee the state won't change until we have the network locked.
|
||||||
|
*/
|
||||||
|
|
||||||
if (psock->s_type != SOCK_STREAM || !_SS_ISCONNECTED(psock->s_flags))
|
if (psock->s_type != SOCK_STREAM)
|
||||||
{
|
{
|
||||||
nerr("ERROR: Not connected\n");
|
nerr("ERROR: Not connected\n");
|
||||||
ret = -ENOTCONN;
|
ret = -ENOTCONN;
|
||||||
@@ -593,6 +596,19 @@ ssize_t psock_tcp_send(FAR struct socket *psock,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
net_lock();
|
net_lock();
|
||||||
|
|
||||||
|
/* Now that we have the network locked, we need to check the connection
|
||||||
|
* state again to ensure the connection is still valid.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!_SS_ISCONNECTED(psock->s_flags))
|
||||||
|
{
|
||||||
|
nerr("ERROR: No longer connected\n");
|
||||||
|
net_unlock();
|
||||||
|
ret = -ENOTCONN;
|
||||||
|
goto errout;
|
||||||
|
}
|
||||||
|
|
||||||
memset(&state, 0, sizeof(struct send_s));
|
memset(&state, 0, sizeof(struct send_s));
|
||||||
|
|
||||||
/* This semaphore is used for signaling and, hence, should not have
|
/* This semaphore is used for signaling and, hence, should not have
|
||||||
|
|||||||
Reference in New Issue
Block a user