From da85d39c0cce2aef20a8dc0c4fdaf3e87e9f5459 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Mon, 2 Apr 2018 10:40:50 -0700 Subject: [PATCH] codec: const-ify socket Avoid possible data race of changing _channel before worker threads are joined. Was just using this as a boolean flag for a method which is already guarded in BlockingTCPTransportCodec::close() from being called twice. --- src/remote/codec.cpp | 4 +--- src/remote/pv/codec.h | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/remote/codec.cpp b/src/remote/codec.cpp index 6e4cb4f..f50ffbc 100644 --- a/src/remote/codec.cpp +++ b/src/remote/codec.cpp @@ -1060,7 +1060,7 @@ void BlockingTCPTransportCodec::waitJoin() void BlockingTCPTransportCodec::internalClose(bool /*force*/) { - if(_channel != INVALID_SOCKET) { + { epicsSocketSystemCallInterruptMechanismQueryInfo info = epicsSocketSystemCallInterruptMechanismQuery (); @@ -1090,8 +1090,6 @@ void BlockingTCPTransportCodec::internalClose(bool /*force*/) default: epicsSocketDestroy(_channel); } - - _channel = INVALID_SOCKET; //TODO: mutex to guard _channel } Transport::shared_pointer thisSharedPtr = this->shared_from_this(); diff --git a/src/remote/pv/codec.h b/src/remote/pv/codec.h index 5b75baa..92c5017 100644 --- a/src/remote/pv/codec.h +++ b/src/remote/pv/codec.h @@ -466,8 +466,8 @@ private: AtomicValue _isOpen; epics::pvData::Thread _readThread, _sendThread; epics::pvData::Event _shutdownEvent; + const SOCKET _channel; protected: - SOCKET _channel; osiSockAddr _socketAddress; std::string _socketName; protected: