avoid data race

destroy() sets _serverSocketChannel=INVALID_SOCKET under the lock.
Other changes are made before the worker thread starts.
This commit is contained in:
Michael Davidsaver
2018-06-26 08:15:50 -07:00
parent 1ba48868f6
commit 4baa72c91d

View File

@@ -165,16 +165,18 @@ void BlockingTCPAcceptor::run() {
while(socketOpen) {
SOCKET sock;
{
Lock guard(_mutex);
if (_destroyed)
break;
sock = _serverSocketChannel;
}
osiSockAddr address;
osiSocklen_t len = sizeof(sockaddr);
SOCKET newClient = epicsSocketAccept(_serverSocketChannel, &address.sa, &len);
SOCKET newClient = epicsSocketAccept(sock, &address.sa, &len);
if(newClient!=INVALID_SOCKET) {
// accept succeeded
ipAddrToDottedIP(&address.ia, ipAddrStr, sizeof(ipAddrStr));