Skip to content

Commit acc5f68

Browse files
Bogdan Marinescuadbridge
authored andcommitted
Don't send events on close()
It's currently possible to generate a socket event when a non-blocking socket is closed: 1. _pending is set to 0 in https://github.com/ARMmbed/mbed-os/blob/master/features/netsocket/TCPSocket.cpp#L22 when the socket is created. 2. close() calls event() in https://github.com/ARMmbed/mbed-os/blob/master/features/netsocket/Socket.cpp#L66 3. event() increments _pending, and since _pending is 1 it will call _callback() in https://github.com/ARMmbed/mbed-os/blob/master/features/netsocket/TCPSocket.cpp#L167 However, if send() (for example) is called, this can happen: - send() is called and sets _pending to 0. - when the data is sent, event() is called, which sets _pending to 1 and calls _callback(). - if close() is called at this point, there won't be an event generated for close() anymore, since _pending will be set to 2. Same thing for recv. Also, same thing for TCPServer and UDPSocket. This PR changes the initial value of _pending to 1 instead of 0, so that events are never generated for close().
1 parent a359a56 commit acc5f68

File tree

6 files changed

+6
-6
lines changed

6 files changed

+6
-6
lines changed

features/netsocket/TCPServer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "mbed.h"
1919

2020
TCPServer::TCPServer()
21-
: _pending(0), _accept_sem(0)
21+
: _pending(1), _accept_sem(0)
2222
{
2323
}
2424

features/netsocket/TCPServer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class TCPServer : public Socket {
4646
*/
4747
template <typename S>
4848
TCPServer(S *stack)
49-
: _pending(0), _accept_sem(0)
49+
: _pending(1), _accept_sem(0)
5050
{
5151
open(stack);
5252
}

features/netsocket/TCPSocket.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "mbed_assert.h"
2020

2121
TCPSocket::TCPSocket()
22-
: _pending(0), _read_sem(0), _write_sem(0),
22+
: _pending(1), _read_sem(0), _write_sem(0),
2323
_read_in_progress(false), _write_in_progress(false)
2424
{
2525
}

features/netsocket/TCPSocket.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class TCPSocket : public Socket {
4545
*/
4646
template <typename S>
4747
TCPSocket(S *stack)
48-
: _pending(0), _read_sem(0), _write_sem(0),
48+
: _pending(1), _read_sem(0), _write_sem(0),
4949
_read_in_progress(false), _write_in_progress(false)
5050
{
5151
open(stack);

features/netsocket/UDPSocket.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "mbed_assert.h"
2020

2121
UDPSocket::UDPSocket()
22-
: _pending(0), _read_sem(0), _write_sem(0)
22+
: _pending(1), _read_sem(0), _write_sem(0)
2323
{
2424
}
2525

features/netsocket/UDPSocket.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class UDPSocket : public Socket {
4545
*/
4646
template <typename S>
4747
UDPSocket(S *stack)
48-
: _pending(0), _read_sem(0), _write_sem(0)
48+
: _pending(1), _read_sem(0), _write_sem(0)
4949
{
5050
open(stack);
5151
}

0 commit comments

Comments
 (0)