From 732fd1f771ed5a37268c89e5d5a72cbe4a62abab Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Mon, 4 Mar 2019 17:54:12 -0800 Subject: [PATCH 01/17] Troubleshoot "no more data in UDP packet" --- src/remote/blockingUDPTransport.cpp | 20 ++++++++++++++++---- src/remote/pv/blockingUDP.h | 5 +---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/remote/blockingUDPTransport.cpp b/src/remote/blockingUDPTransport.cpp index f0fca62..cc4d070 100644 --- a/src/remote/blockingUDPTransport.cpp +++ b/src/remote/blockingUDPTransport.cpp @@ -9,6 +9,8 @@ #include #endif +#include + #include #include @@ -113,6 +115,16 @@ void BlockingUDPTransport::close() { close(true); } +void BlockingUDPTransport::ensureData(std::size_t size) { + if (_receiveBuffer.getRemaining() >= size) + return; + std::ostringstream msg; + msg<<"no more data in UDP packet : " + <<_receiveBuffer.getPosition()<<":"<<_receiveBuffer.getLimit() + <<" for "< Date: Wed, 6 Mar 2019 10:32:53 -0800 Subject: [PATCH 02/17] redo hexDump ludicrously inefficient (cf. toHex() ), and inflexible. --- src/remote/abstractResponseHandler.cpp | 16 +-- src/remote/codec.cpp | 21 ---- src/remoteClient/clientContextImpl.cpp | 12 ++- src/server/responseHandlers.cpp | 14 ++- src/utils/hexDump.cpp | 144 ++++++++++++------------- src/utils/pv/hexDump.h | 51 ++++----- testApp/utils/testHexDump.cpp | 20 ++-- 7 files changed, 121 insertions(+), 157 deletions(-) diff --git a/src/remote/abstractResponseHandler.cpp b/src/remote/abstractResponseHandler.cpp index 71790e4..1a494f0 100644 --- a/src/remote/abstractResponseHandler.cpp +++ b/src/remote/abstractResponseHandler.cpp @@ -4,8 +4,6 @@ * in file LICENSE that is included with this distribution. */ -#include - #include #include @@ -15,9 +13,6 @@ #include #include -using std::ostringstream; -using std::hex; - using namespace epics::pvData; namespace epics { @@ -44,13 +39,10 @@ void ResponseHandler::handleResponse(osiSockAddr* responseFrom, char ipAddrStr[48]; ipAddrToDottedIP(&responseFrom->ia, ipAddrStr, sizeof(ipAddrStr)); - ostringstream prologue; - prologue<<"Message [0x"<getRemoteName(); - - hexDump(prologue.str(), _description, - (const int8*)payloadBuffer->getArray(), - payloadBuffer->getPosition(), static_cast(payloadSize)); + std::cerr<<"Message [0x"<getRemoteName() + <<" : "<<_description<<"\n" + <getArray(), - buffer->getPosition(), buffer->getRemaining()); - } - */ - if (bytesSent < 0) { // connection lost @@ -1302,13 +1288,6 @@ int BlockingTCPTransportCodec::read(epics::pvData::ByteBuffer* dst) { // NOTE: do not log here, you might override SOCKERRNO relevant to recv() operation above - /* - if (IS_LOGGABLE(logLevelTrace)) { - hexDump(std::string("READ"), - (const int8 *)(dst->getArray()+pos), bytesRead); - } - */ - if(unlikely(bytesRead<=0)) { if (bytesRead<0) diff --git a/src/remoteClient/clientContextImpl.cpp b/src/remoteClient/clientContextImpl.cpp index bea6744..68f507d 100644 --- a/src/remoteClient/clientContextImpl.cpp +++ b/src/remoteClient/clientContextImpl.cpp @@ -2998,10 +2998,14 @@ public: { if (command < 0 || command >= (int8)m_handlerTable.size()) { - // TODO remove debug output - char buf[100]; - sprintf(buf, "Invalid (or unsupported) command %d, its payload", command); - hexDump(buf, (const int8*)(payloadBuffer->getArray()), payloadBuffer->getPosition(), payloadSize); + LOG(logLevelError, + "Invalid (or unsupported) command: %x.", (0xFF&command)); + + if(pvAccessIsLoggable(logLevelError)) { + std::cerr<<"Invalid PVA header "<=(int8)m_handlerTable.size()) { - LOG(logLevelDebug, + LOG(logLevelError, "Invalid (or unsupported) command: %x.", (0xFF&command)); - // TODO remove debug output - std::ostringstream name; - name<<"Invalid PVA header "<getArray(), - payloadBuffer->getPosition(), payloadSize); + if(pvAccessIsLoggable(logLevelError)) { + std::cerr<<"Invalid PVA header "< #include #include +#include +#include + +#include #define epicsExportSharedSymbols #include -using namespace epics::pvData; -using std::string; -using std::stringstream; -using std::endl; -using std::cout; - namespace epics { namespace pvAccess { -/// Byte to hexchar mapping. -static const char lookup[] = { - '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' -}; +HexDump::HexDump(const char* buf, size_t len) + :buf(buf) + ,buflen(len) + ,_limit(1024u) + ,_groupBy(4u) + ,_perLine(16u) +{} -/// Get hex representation of byte. -string toHex(int8 b) { - string sb; - - int upper = (b>>4)&0x0F; - sb += lookup[upper]; - - int lower = b&0x0F; - sb += lookup[lower]; - - sb += ' '; - - return sb; +HexDump::HexDump(const pvData::ByteBuffer& bb, + size_t size, size_t offset) + :buf(bb.getBuffer() + bb.getPosition()) + ,buflen(bb.getRemaining()) + ,_limit((size_t)-1) + ,_groupBy(4u) + ,_perLine(16u) +{ + if(offset > buflen) + offset = buflen; + buf += offset; + buflen -= offset; + if(buflen > size) + buflen = size; } -/// Get ASCII representation of byte, dot if non-readable. -char toAscii(int8 b) { - if(b>(int8)31&&b<(int8)127) - return (char)b; - else - return '.'; +HexDump::~HexDump() {} + +static +size_t ilog2(size_t val) +{ + size_t ret = 0; + while(val >>= 1) + ret++; + return ret; } -void hexDump(std::string const & name, const int8 *bs, int len) { - hexDump(name, bs, 0, len); +static +size_t bits2bytes(size_t val) +{ + // round up to next multiple of 8 + val -= 1u; + val |= 7u; + val += 1u; + // bits -> bytes + val /= 8u; + return val; } -void hexDump(std::string const & name, const int8 *bs, int start, int len) { - hexDump("", name, bs, start, len); -} +epicsShareFunc +std::ostream& operator<<(std::ostream& strm, const HexDump& hex) +{ + size_t len = std::min(hex.buflen, hex._limit); + // find address width in hex chars + // find bit width, rounded up to 8 bits, divide down to bytes + size_t addrwidth = bits2bytes(ilog2(len))*2u; -void hexDump(std::string const & prologue, string const & name, const int8 *bs, - int start, int len) { + for(size_t i=0; i + #ifdef epicsExportSharedSymbols # define hexDumpEpicsExportSharedSymbols # undef epicsExportSharedSymbols @@ -22,35 +24,34 @@ #include namespace epics { +namespace pvData { +class ByteBuffer; +} namespace pvAccess { -/** - * Output a buffer in hex format. - * @param name name (description) of the message. - * @param bs buffer to dump - * @param len first bytes (length) to dump. - */ -epicsShareFunc void hexDump(std::string const & name, const epics::pvData::int8 *bs, int len); +class epicsShareClass HexDump { + const char* buf; + size_t buflen; + size_t _limit; + unsigned _groupBy; + unsigned _perLine; +public: + HexDump(const char* buf, size_t len); + explicit HexDump(const pvData::ByteBuffer& buf, size_t size=(size_t)-1, size_t offset=0u); + ~HexDump(); -/** - * Output a buffer in hex format. - * @param[in] name name (description) of the message. - * @param[in] bs buffer to dump - * @param[in] start dump message using given offset. - * @param[in] len first bytes (length) to dump. - */ -epicsShareFunc void hexDump(std::string const & name, const epics::pvData::int8 *bs, int start, int len); + //! safety limit on max bytes printed + inline HexDump& limit(size_t n=(size_t)-1) { _limit = n; return *this; } + //! insert a space after this many bytes + inline HexDump& bytesPerGroup(size_t n=(size_t)-1) { _groupBy = n; return *this; } + //! start a new line after this many bytes + inline HexDump& bytesPerLine(size_t n=(size_t)-1) { _perLine = n; return *this; } -/** - * Output a buffer in hex format. - * @param[in] prologue string to prefixed to debug output, can be null - * @param[in] name name (description) of the message. - * @param[in] bs buffer to dump - * @param[in] start dump message using given offset. - * @param[in] len first bytes (length) to dump. - */ -epicsShareFunc void hexDump(std::string const & prologue, std::string const & name, - const epics::pvData::int8 *bs, int start, int len); + friend std::ostream& operator<<(std::ostream& strm, const HexDump& hex); +}; + +epicsShareFunc +std::ostream& operator<<(std::ostream& strm, const HexDump& hex); } } diff --git a/testApp/utils/testHexDump.cpp b/testApp/utils/testHexDump.cpp index d4cf207..bd10005 100644 --- a/testApp/utils/testHexDump.cpp +++ b/testApp/utils/testHexDump.cpp @@ -1,6 +1,9 @@ -#include + +#include + #include +#include #include using namespace epics::pvData; @@ -8,19 +11,16 @@ using namespace epics::pvAccess; MAIN(testHexDump) { - testPlan(3); + testPlan(1); testDiag("Tests for hexDump"); - char TO_DUMP[] = "pvAccess dump test\0\1\2\3\4\5\6\254\255\256"; + char TO_DUMP[] = "pvAccess dump test\0\1\2\3\4\5\6\xfd\xfe\xff"; - hexDump("test", (int8*)TO_DUMP, 18+9); - testPass("Entire array"); + std::ostringstream msg; + msg< Date: Wed, 6 Mar 2019 09:30:14 -0800 Subject: [PATCH 03/17] more Troubleshoot "no more data in UDP packet" --- src/remote/abstractResponseHandler.cpp | 2 +- src/remote/blockingUDPTransport.cpp | 20 +++++++++++++------- src/remoteClient/clientContextImpl.cpp | 10 +++------- src/server/responseHandlers.cpp | 7 +++---- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/remote/abstractResponseHandler.cpp b/src/remote/abstractResponseHandler.cpp index 1a494f0..f2d5f2d 100644 --- a/src/remote/abstractResponseHandler.cpp +++ b/src/remote/abstractResponseHandler.cpp @@ -42,7 +42,7 @@ void ResponseHandler::handleResponse(osiSockAddr* responseFrom, std::cerr<<"Message [0x"<getRemoteName() <<" : "<<_description<<"\n" - < #include #include +#include using namespace epics::pvData; using namespace std; @@ -267,13 +268,18 @@ void BlockingUDPTransport::run() { try { processBuffer(thisTransport, fromAddress, &_receiveBuffer); } catch(std::exception& e) { - LOG(logLevelError, - "an exception caught while in UDP receiveThread %s at %s:%d: %s", - _remoteName.c_str(), __FILE__, __LINE__, e.what()); - } catch (...) { - LOG(logLevelError, - "unknown exception caught while in UDP receiveThread %s at %s:%d.", - _remoteName.c_str(), __FILE__, __LINE__); + if(IS_LOGGABLE(logLevelError)) { + char strBuffer[64]; + sockAddrToDottedIP(&fromAddress.sa, strBuffer, sizeof(strBuffer)); + size_t epos = _receiveBuffer.getPosition(); + + // of course _receiveBuffer _may_ have been modified during processing... + _receiveBuffer.setPosition(RECEIVE_BUFFER_PRE_RESERVE); + _receiveBuffer.setLimit(RECEIVE_BUFFER_PRE_RESERVE+bytesRead); + + std::cerr<<"Error on UDP RX "< "<<_remoteName<<" at "<= (int8)m_handlerTable.size()) { - LOG(logLevelError, - "Invalid (or unsupported) command: %x.", (0xFF&command)); - - if(pvAccessIsLoggable(logLevelError)) { - std::cerr<<"Invalid PVA header "< Date: Wed, 6 Mar 2019 15:52:49 -0800 Subject: [PATCH 04/17] ignore protocol minor version 0 The change from 0 -> 1 included incompatible changes to CMD_BEACON and several others. Ignore any UDP messages (beacon or search), and disconnect any TCP peers, with version==0. --- pvtoolsSrc/pvlist.cpp | 4 ++++ src/remote/blockingUDPTransport.cpp | 4 ++++ src/remote/codec.cpp | 8 ++++---- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pvtoolsSrc/pvlist.cpp b/pvtoolsSrc/pvlist.cpp index 573ebe3..ddc42ac 100644 --- a/pvtoolsSrc/pvlist.cpp +++ b/pvtoolsSrc/pvlist.cpp @@ -120,6 +120,10 @@ bool processSearchResponse(osiSockAddr const & responseFrom, ByteBuffer & receiv // second byte version int8 version = receiveBuffer.getByte(); + if(version == 0) { + // 0 -> 1 included incompatible changes + return false; + } // only data for UDP int8 flags = receiveBuffer.getByte(); diff --git a/src/remote/blockingUDPTransport.cpp b/src/remote/blockingUDPTransport.cpp index db0e366..77c0797 100644 --- a/src/remote/blockingUDPTransport.cpp +++ b/src/remote/blockingUDPTransport.cpp @@ -341,6 +341,10 @@ bool BlockingUDPTransport::processBuffer(Transport::shared_pointer const & trans // second byte version int8 version = receiveBuffer->getByte(); + if(version==0) { + // 0 -> 1 included incompatible changes + return false; + } int8 flags = receiveBuffer->getByte(); if (flags & 0x80) diff --git a/src/remote/codec.cpp b/src/remote/codec.cpp index 0ee4c11..e4ad3a4 100644 --- a/src/remote/codec.cpp +++ b/src/remote/codec.cpp @@ -159,12 +159,12 @@ void AbstractCodec::processHeader() { _payloadSize = _socketBuffer.getInt(); // check magic code - if (magicCode != PVA_MAGIC) + if (magicCode != PVA_MAGIC || _version==0) { LOG(logLevelError, - "Invalid header received from the client at %s:%d: %s.," - " disconnecting...", - __FILE__, __LINE__, inetAddressToString(*getLastReadBufferSocketAddress()).c_str()); + "Invalid header received from the client : %s %02x%02x%02x%02x disconnecting...", + inetAddressToString(*getLastReadBufferSocketAddress()).c_str(), + unsigned(magicCode), unsigned(_version), unsigned(_flags), unsigned(_command)); invalidDataStreamHandler(); throw invalid_data_stream_exception("invalid header received"); } From 64453e1f1a7da92e46b569b859152ebad893d6a4 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Sat, 18 May 2019 18:23:17 -0700 Subject: [PATCH 05/17] split client/server protocol version --- pvtoolsSrc/pvlist.cpp | 2 +- src/pva/pv/pvaConstants.h | 9 +- src/remote/blockingUDPTransport.cpp | 12 ++- src/remote/channelSearchManager.cpp | 2 +- src/remote/codec.cpp | 6 +- src/remote/pv/codec.h | 6 +- src/remoteClient/clientContextImpl.cpp | 2 +- testApp/remote/testCodec.cpp | 124 ++++++++++++------------- 8 files changed, 86 insertions(+), 77 deletions(-) diff --git a/pvtoolsSrc/pvlist.cpp b/pvtoolsSrc/pvlist.cpp index ddc42ac..dc6a029 100644 --- a/pvtoolsSrc/pvlist.cpp +++ b/pvtoolsSrc/pvlist.cpp @@ -337,7 +337,7 @@ bool discoverServers(double timeOut) ByteBuffer sendBuffer(buffer, sizeof(buffer)/sizeof(char)); sendBuffer.putByte(PVA_MAGIC); - sendBuffer.putByte(PVA_VERSION); + sendBuffer.putByte(PVA_CLIENT_PROTOCOL_REVISION); sendBuffer.putByte((EPICS_BYTE_ORDER == EPICS_ENDIAN_BIG) ? 0x80 : 0x00); // data + 7-bit endianess sendBuffer.putByte((int8_t)CMD_SEARCH); // search sendBuffer.putInt(4+1+3+16+2+1+2); // "zero" payload diff --git a/src/pva/pv/pvaConstants.h b/src/pva/pv/pvaConstants.h index d090141..e16fd5e 100644 --- a/src/pva/pv/pvaConstants.h +++ b/src/pva/pv/pvaConstants.h @@ -7,6 +7,8 @@ #ifndef PVACONSTANTS_H_ #define PVACONSTANTS_H_ +#include + #ifdef epicsExportSharedSymbols # define pvaConstantsepicsExportSharedSymbols # undef epicsExportSharedSymbols @@ -26,11 +28,14 @@ namespace pvAccess { /** PVA protocol magic number */ const epics::pvData::int8 PVA_MAGIC = static_cast(0xCA); +const epics::pvData::int8 PVA_SERVER_PROTOCOL_REVISION = 1; +const epics::pvData::int8 PVA_CLIENT_PROTOCOL_REVISION = 1; + /** PVA protocol revision (implemented by this library). */ -const epics::pvData::int8 PVA_PROTOCOL_REVISION = 1; +const epics::pvData::int8 PVA_PROTOCOL_REVISION EPICS_DEPRECATED = 1; /** PVA version signature used to report this implementation version in header. */ -const epics::pvData::int8 PVA_VERSION = PVA_PROTOCOL_REVISION; +const epics::pvData::int8 PVA_VERSION EPICS_DEPRECATED = 1; /** Default PVA server port. */ const epics::pvData::int32 PVA_SERVER_PORT = 5075; diff --git a/src/remote/blockingUDPTransport.cpp b/src/remote/blockingUDPTransport.cpp index 77c0797..0293806 100644 --- a/src/remote/blockingUDPTransport.cpp +++ b/src/remote/blockingUDPTransport.cpp @@ -207,7 +207,7 @@ void BlockingUDPTransport::flushSendQueue() void BlockingUDPTransport::startMessage(int8 command, size_t /*ensureCapacity*/, int32 payloadSize) { _lastMessageStartPosition = _sendBuffer.getPosition(); _sendBuffer.putByte(PVA_MAGIC); - _sendBuffer.putByte(PVA_VERSION); + _sendBuffer.putByte((_clientServerWithEndianFlag&0x40) ? PVA_SERVER_PROTOCOL_REVISION : PVA_CLIENT_PROTOCOL_REVISION); _sendBuffer.putByte(_clientServerWithEndianFlag); _sendBuffer.putByte(command); // command _sendBuffer.putInt(payloadSize); @@ -580,6 +580,8 @@ void initializeUDPTransports(bool serverFlag, { BlockingUDPConnector connector(serverFlag); + const int8_t protoVer = serverFlag ? PVA_SERVER_PROTOCOL_REVISION : PVA_CLIENT_PROTOCOL_REVISION; + // // Create UDP transport for sending (to all network interfaces) // @@ -590,7 +592,7 @@ void initializeUDPTransports(bool serverFlag, anyAddress.ia.sin_port = htons(0); anyAddress.ia.sin_addr.s_addr = htonl(INADDR_ANY); - sendTransport = connector.connect(responseHandler, anyAddress, PVA_PROTOCOL_REVISION); + sendTransport = connector.connect(responseHandler, anyAddress, protoVer); if (!sendTransport) { THROW_BASE_EXCEPTION("Failed to initialize UDP transport."); @@ -730,7 +732,7 @@ void initializeUDPTransports(bool serverFlag, listenLocalAddress.ia.sin_addr.s_addr = node.addr.ia.sin_addr.s_addr; BlockingUDPTransport::shared_pointer transport = connector.connect( - responseHandler, listenLocalAddress, PVA_PROTOCOL_REVISION); + responseHandler, listenLocalAddress, protoVer); if (!transport) continue; listenLocalAddress = transport->getRemoteAddress(); @@ -764,7 +766,7 @@ void initializeUDPTransports(bool serverFlag, bcastAddress.ia.sin_port = htons(listenPort); bcastAddress.ia.sin_addr.s_addr = node.bcast.ia.sin_addr.s_addr; - transport2 = connector.connect(responseHandler, bcastAddress, PVA_PROTOCOL_REVISION); + transport2 = connector.connect(responseHandler, bcastAddress, protoVer); if (transport2) { /* The other wrinkle is that nothing should be sent from this second @@ -824,7 +826,7 @@ void initializeUDPTransports(bool serverFlag, #else anyAddress, #endif - PVA_PROTOCOL_REVISION); + protoVer); if (!localMulticastTransport) throw std::runtime_error("Failed to bind UDP socket."); diff --git a/src/remote/channelSearchManager.cpp b/src/remote/channelSearchManager.cpp index a11cd4e..ec97ae8 100644 --- a/src/remote/channelSearchManager.cpp +++ b/src/remote/channelSearchManager.cpp @@ -206,7 +206,7 @@ void ChannelSearchManager::initializeSendBuffer() // new buffer m_sendBuffer.clear(); m_sendBuffer.putByte(PVA_MAGIC); - m_sendBuffer.putByte(PVA_VERSION); + m_sendBuffer.putByte(PVA_CLIENT_PROTOCOL_REVISION); m_sendBuffer.putByte((EPICS_BYTE_ORDER == EPICS_ENDIAN_BIG) ? 0x80 : 0x00); // data + 7-bit endianess m_sendBuffer.putByte(CMD_SEARCH); m_sendBuffer.putInt(4+1+3+16+2+1); // "zero" payload diff --git a/src/remote/codec.cpp b/src/remote/codec.cpp index e4ad3a4..19d5975 100644 --- a/src/remote/codec.cpp +++ b/src/remote/codec.cpp @@ -591,7 +591,7 @@ void AbstractCodec::startMessage( PVA_MESSAGE_HEADER_SIZE + ensureCapacity + _nextMessagePayloadOffset); _lastMessageStartPosition = _sendBuffer.getPosition(); _sendBuffer.putByte(PVA_MAGIC); - _sendBuffer.putByte(PVA_VERSION); + _sendBuffer.putByte(_clientServerFlag ? PVA_SERVER_PROTOCOL_REVISION : PVA_CLIENT_PROTOCOL_REVISION); _sendBuffer.putByte( (_lastSegmentedMessageType | _byteOrderFlag | _clientServerFlag)); // data message _sendBuffer.putByte(command); // command @@ -612,7 +612,7 @@ void AbstractCodec::putControlMessage( std::numeric_limits::max(); // TODO revise this ensureBuffer(PVA_MESSAGE_HEADER_SIZE); _sendBuffer.putByte(PVA_MAGIC); - _sendBuffer.putByte(PVA_VERSION); + _sendBuffer.putByte(_clientServerFlag ? PVA_SERVER_PROTOCOL_REVISION : PVA_CLIENT_PROTOCOL_REVISION); _sendBuffer.putByte((0x01 | _byteOrderFlag | _clientServerFlag)); // control message _sendBuffer.putByte(command); // command _sendBuffer.putInt(data); // data @@ -1472,7 +1472,7 @@ void BlockingServerTCPTransportCodec::send(ByteBuffer* buffer, ensureBuffer(PVA_MESSAGE_HEADER_SIZE); buffer->putByte(PVA_MAGIC); - buffer->putByte(PVA_VERSION); + buffer->putByte(PVA_SERVER_PROTOCOL_REVISION); buffer->putByte( 0x01 | 0x40 | ((EPICS_BYTE_ORDER == EPICS_ENDIAN_BIG) ? 0x80 : 0x00)); // control + server + endian diff --git a/src/remote/pv/codec.h b/src/remote/pv/codec.h index c8138dc..6265d42 100644 --- a/src/remote/pv/codec.h +++ b/src/remote/pv/codec.h @@ -289,7 +289,9 @@ private: std::size_t _nextMessagePayloadOffset; epics::pvData::int8 _byteOrderFlag; +protected: epics::pvData::int8 _clientServerFlag; +private: const size_t _socketSendBufferSize; public: @@ -365,8 +367,8 @@ public: epics::pvData::int8 getRevision() const { epicsGuard G(_mutex); - return PVA_PROTOCOL_REVISION < _version - ? PVA_PROTOCOL_REVISION : _version; + int8_t myver = _clientServerFlag ? PVA_SERVER_PROTOCOL_REVISION : PVA_CLIENT_PROTOCOL_REVISION; + return myver < _version ? myver : _version; } diff --git a/src/remoteClient/clientContextImpl.cpp b/src/remoteClient/clientContextImpl.cpp index 13d2236..57f2237 100644 --- a/src/remoteClient/clientContextImpl.cpp +++ b/src/remoteClient/clientContextImpl.cpp @@ -3597,7 +3597,7 @@ public: // NOTE: calls channelConnectFailed() on failure static ServerGUID guid = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }; // m_addresses[ix] is modified by the following - searchResponse(guid, PVA_PROTOCOL_REVISION, &m_addresses[ix]); + searchResponse(guid, PVA_CLIENT_PROTOCOL_REVISION, &m_addresses[ix]); } virtual void timerStopped() OVERRIDE FINAL { diff --git a/testApp/remote/testCodec.cpp b/testApp/remote/testCodec.cpp index 74cb62c..ba8447d 100644 --- a/testApp/remote/testCodec.cpp +++ b/testApp/remote/testCodec.cpp @@ -483,7 +483,7 @@ private: TestCodec codec(DEFAULT_BUFFER_SIZE,DEFAULT_BUFFER_SIZE); codec._readBuffer->put(PVA_MAGIC); - codec._readBuffer->put(PVA_VERSION); + codec._readBuffer->put(PVA_CLIENT_PROTOCOL_REVISION); codec._readBuffer->put((int8_t)0x01); codec._readBuffer->put((int8_t)0x23); codec._readBuffer->putInt(0x456789AB); @@ -506,8 +506,8 @@ private: PVAMessage header = codec._receivedControlMessages[0]; - testOk(header._version == PVA_VERSION, - "%s: header._version == PVA_VERSION", CURRENT_FUNCTION); + testOk(header._version == PVA_CLIENT_PROTOCOL_REVISION, + "%s: header._version == PVA_CLIENT_PROTOCOL_REVISION", CURRENT_FUNCTION); testOk(codec._invalidDataStreamCount == 0, "%s: codec._invalidDataStreamCount == 0", @@ -523,13 +523,13 @@ private: // two at the time, app and control codec._readBuffer->put(PVA_MAGIC); - codec._readBuffer->put(PVA_VERSION); + codec._readBuffer->put(PVA_CLIENT_PROTOCOL_REVISION); codec._readBuffer->put((int8_t)0x00); codec._readBuffer->put((int8_t)0x20); codec._readBuffer->putInt(0x00000000); codec._readBuffer->put(PVA_MAGIC); - codec._readBuffer->put(PVA_VERSION); + codec._readBuffer->put(PVA_CLIENT_PROTOCOL_REVISION); codec._readBuffer->put((int8_t)0x81); codec._readBuffer->put((int8_t)0xEE); codec._readBuffer->putInt(0xDDCCBBAA); @@ -553,8 +553,8 @@ private: // app, no payload header = codec._receivedAppMessages[0]; - testOk(header._version == PVA_VERSION, - "%s: header._version == PVA_VERSION", CURRENT_FUNCTION); + testOk(header._version == PVA_CLIENT_PROTOCOL_REVISION, + "%s: header._version == PVA_CLIENT_PROTOCOL_REVISION", CURRENT_FUNCTION); testOk(header._flags == (int8_t)0x00, "%s: header._flags == 0x00", CURRENT_FUNCTION); testOk(header._command == (int8_t)0x20, @@ -565,8 +565,8 @@ private: // control header = codec._receivedControlMessages[0]; - testOk(header._version == PVA_VERSION, - "%s: header._version == PVA_VERSION", CURRENT_FUNCTION); + testOk(header._version == PVA_CLIENT_PROTOCOL_REVISION, + "%s: header._version == PVA_CLIENT_PROTOCOL_REVISION", CURRENT_FUNCTION); testOk(header._flags == (int8_t)0x81, "%s: header._flags == 0x81", CURRENT_FUNCTION); testOk(header._command == (int8_t)0xEE, @@ -585,7 +585,7 @@ private: TestCodec codec(DEFAULT_BUFFER_SIZE,DEFAULT_BUFFER_SIZE); codec._readBuffer->put((int8_t)00); - codec._readBuffer->put(PVA_VERSION); + codec._readBuffer->put(PVA_CLIENT_PROTOCOL_REVISION); codec._readBuffer->put((int8_t)0x01); codec._readBuffer->put((int8_t)0x23); codec._readBuffer->putInt(0x456789AB); @@ -621,7 +621,7 @@ private: { TestCodec codec(DEFAULT_BUFFER_SIZE,DEFAULT_BUFFER_SIZE); codec._readBuffer->put(PVA_MAGIC); - codec._readBuffer->put(PVA_VERSION); + codec._readBuffer->put(PVA_CLIENT_PROTOCOL_REVISION); codec._readBuffer->put(invalidFlagsValues[i]); codec._readBuffer->put((int8_t)0x23); //codec._readBuffer->putInt(0); @@ -653,7 +653,7 @@ private: TestCodec codec(DEFAULT_BUFFER_SIZE,DEFAULT_BUFFER_SIZE); codec._readBuffer->put(PVA_MAGIC); - codec._readBuffer->put(PVA_VERSION); + codec._readBuffer->put(PVA_CLIENT_PROTOCOL_REVISION); codec._readBuffer->put((int8_t)0x80); codec._readBuffer->put((int8_t)0x23); codec._readBuffer->putInt(0x456789AB); @@ -682,7 +682,7 @@ private: TestCodec codec(DEFAULT_BUFFER_SIZE,DEFAULT_BUFFER_SIZE); codec._readBuffer->put(PVA_MAGIC); - codec._readBuffer->put(PVA_VERSION); + codec._readBuffer->put(PVA_CLIENT_PROTOCOL_REVISION); codec._readBuffer->put((int8_t)0x01); codec._readBuffer->flip(); @@ -724,8 +724,8 @@ private: // app, no payload PVAMessage header = codec._receivedControlMessages[0]; - testOk(header._version == PVA_VERSION, - "%s: header._version == PVA_VERSION", CURRENT_FUNCTION); + testOk(header._version == PVA_CLIENT_PROTOCOL_REVISION, + "%s: header._version == PVA_CLIENT_PROTOCOL_REVISION", CURRENT_FUNCTION); testOk(header._flags == (int8_t)0x01, "%s: header._flags == 0x01", CURRENT_FUNCTION); testOk(header._command == (int8_t)0x23, @@ -744,7 +744,7 @@ private: codec._readPayload = true; codec._readBuffer->put(PVA_MAGIC); - codec._readBuffer->put(PVA_VERSION); + codec._readBuffer->put(PVA_CLIENT_PROTOCOL_REVISION); codec._readBuffer->put((int8_t)0x80); codec._readBuffer->put((int8_t)0x23); codec._readBuffer->putInt(1); // size @@ -790,7 +790,7 @@ private: codec._readPayload = true; codec._readBuffer->put(PVA_MAGIC); - codec._readBuffer->put(PVA_VERSION); + codec._readBuffer->put(PVA_CLIENT_PROTOCOL_REVISION); codec._readBuffer->put((int8_t)0x80); codec._readBuffer->put((int8_t)0x23); const int32_t payloadSize1 = 2; @@ -806,7 +806,7 @@ private: codec._readBuffer->put(PVA_MAGIC); - codec._readBuffer->put(PVA_VERSION); + codec._readBuffer->put(PVA_CLIENT_PROTOCOL_REVISION); codec._readBuffer->put((int8_t)0x80); codec._readBuffer->put((int8_t)0x45); @@ -912,7 +912,7 @@ private: _codec._readBuffer->put(PVA_MAGIC); - _codec._readBuffer->put(PVA_VERSION); + _codec._readBuffer->put(PVA_CLIENT_PROTOCOL_REVISION); _codec._readBuffer->put((int8_t)0x80); _codec._readBuffer->put((int8_t)0x45); _codec._readBuffer->putInt(_payloadSize2); @@ -958,7 +958,7 @@ private: // 1st codec._readBuffer->put(PVA_MAGIC); - codec._readBuffer->put(PVA_VERSION); + codec._readBuffer->put(PVA_CLIENT_PROTOCOL_REVISION); codec._readBuffer->put((int8_t)0x90); codec._readBuffer->put((int8_t)0x01); @@ -971,7 +971,7 @@ private: // 2nd codec._readBuffer->put(PVA_MAGIC); - codec._readBuffer->put(PVA_VERSION); + codec._readBuffer->put(PVA_CLIENT_PROTOCOL_REVISION); codec._readBuffer->put((int8_t)0xB0); codec._readBuffer->put((int8_t)0x01); @@ -983,14 +983,14 @@ private: // control in between codec._readBuffer->put(PVA_MAGIC); - codec._readBuffer->put(PVA_VERSION); + codec._readBuffer->put(PVA_CLIENT_PROTOCOL_REVISION); codec._readBuffer->put((int8_t)0x81); codec._readBuffer->put((int8_t)0xEE); codec._readBuffer->putInt(0xDDCCBBAA); // 3rd codec._readBuffer->put(PVA_MAGIC); - codec._readBuffer->put(PVA_VERSION); + codec._readBuffer->put(PVA_CLIENT_PROTOCOL_REVISION); codec._readBuffer->put((int8_t)0xB0); codec._readBuffer->put((int8_t)0x01); @@ -1002,7 +1002,7 @@ private: // 4t (last) codec._readBuffer->put(PVA_MAGIC); - codec._readBuffer->put(PVA_VERSION); + codec._readBuffer->put(PVA_CLIENT_PROTOCOL_REVISION); codec._readBuffer->put((int8_t)0xA0); codec._readBuffer->put((int8_t)0x01); @@ -1057,8 +1057,8 @@ private: msg = codec._receivedControlMessages[0]; - testOk(msg._version == PVA_VERSION, - "%s: msg._version == PVA_VERSION", CURRENT_FUNCTION); + testOk(msg._version == PVA_CLIENT_PROTOCOL_REVISION, + "%s: msg._version == PVA_CLIENT_PROTOCOL_REVISION", CURRENT_FUNCTION); testOk(msg._flags == (int8_t)0x81, "%s: msg._flags == 0x81", CURRENT_FUNCTION); testOk(msg._command == (int8_t)0xEE, @@ -1078,7 +1078,7 @@ private: // 1st codec._readBuffer->put(PVA_MAGIC); - codec._readBuffer->put(PVA_VERSION); + codec._readBuffer->put(PVA_CLIENT_PROTOCOL_REVISION); codec._readBuffer->put((int8_t)0x90); codec._readBuffer->put((int8_t)0x01); @@ -1091,7 +1091,7 @@ private: // 2nd codec._readBuffer->put(PVA_MAGIC); - codec._readBuffer->put(PVA_VERSION); + codec._readBuffer->put(PVA_CLIENT_PROTOCOL_REVISION); // invalid flag, should be 0xB0 codec._readBuffer->put((int8_t)0x90); codec._readBuffer->put((int8_t)0x01); @@ -1104,14 +1104,14 @@ private: // control in between codec._readBuffer->put(PVA_MAGIC); - codec._readBuffer->put(PVA_VERSION); + codec._readBuffer->put(PVA_CLIENT_PROTOCOL_REVISION); codec._readBuffer->put((int8_t)0x81); codec._readBuffer->put((int8_t)0xEE); codec._readBuffer->putInt(0xDDCCBBAA); // 3rd codec._readBuffer->put(PVA_MAGIC); - codec._readBuffer->put(PVA_VERSION); + codec._readBuffer->put(PVA_CLIENT_PROTOCOL_REVISION); codec._readBuffer->put((int8_t)0xB0); codec._readBuffer->put((int8_t)0x01); @@ -1123,7 +1123,7 @@ private: // 4t (last) codec._readBuffer->put(PVA_MAGIC); - codec._readBuffer->put(PVA_VERSION); + codec._readBuffer->put(PVA_CLIENT_PROTOCOL_REVISION); codec._readBuffer->put((int8_t)0xA0); codec._readBuffer->put((int8_t)0x01); @@ -1172,7 +1172,7 @@ private: // 1st codec._readBuffer->put(PVA_MAGIC); - codec._readBuffer->put(PVA_VERSION); + codec._readBuffer->put(PVA_CLIENT_PROTOCOL_REVISION); codec._readBuffer->put((int8_t)0x90); codec._readBuffer->put((int8_t)0x01); @@ -1190,7 +1190,7 @@ private: // 2nd codec._readBuffer->put(PVA_MAGIC); - codec._readBuffer->put(PVA_VERSION); + codec._readBuffer->put(PVA_CLIENT_PROTOCOL_REVISION); codec._readBuffer->put((int8_t)0xB0); codec._readBuffer->put((int8_t)0x01); @@ -1209,7 +1209,7 @@ private: // 3rd codec._readBuffer->put(PVA_MAGIC); - codec._readBuffer->put(PVA_VERSION); + codec._readBuffer->put(PVA_CLIENT_PROTOCOL_REVISION); codec._readBuffer->put((int8_t)0xB0); codec._readBuffer->put((int8_t)0x01); @@ -1227,7 +1227,7 @@ private: // 4t (last) codec._readBuffer->put(PVA_MAGIC); - codec._readBuffer->put(PVA_VERSION); + codec._readBuffer->put(PVA_CLIENT_PROTOCOL_REVISION); codec._readBuffer->put((int8_t)0xA0); codec._readBuffer->put((int8_t)0x01); @@ -1339,7 +1339,7 @@ private: // 1st codec._readBuffer->put(PVA_MAGIC); - codec._readBuffer->put(PVA_VERSION); + codec._readBuffer->put(PVA_CLIENT_PROTOCOL_REVISION); codec._readBuffer->put((int8_t)0x90); codec._readBuffer->put((int8_t)0x01); @@ -1357,7 +1357,7 @@ private: // 2nd codec._readBuffer->put(PVA_MAGIC); - codec._readBuffer->put(PVA_VERSION); + codec._readBuffer->put(PVA_CLIENT_PROTOCOL_REVISION); codec._readBuffer->put((int8_t)0xB0); codec._readBuffer->put((int8_t)0x01); @@ -1377,7 +1377,7 @@ private: // 3rd codec._readBuffer->put(PVA_MAGIC); - codec._readBuffer->put(PVA_VERSION); + codec._readBuffer->put(PVA_CLIENT_PROTOCOL_REVISION); codec._readBuffer->put((int8_t)0xA0); codec._readBuffer->put((int8_t)0x01); @@ -1499,8 +1499,8 @@ private: PVAMessage header = codec._receivedControlMessages[0]; - testOk(header._version == PVA_VERSION, - "%s: header._version == PVA_VERSION", CURRENT_FUNCTION); + testOk(header._version == PVA_CLIENT_PROTOCOL_REVISION, + "%s: header._version == PVA_CLIENT_PROTOCOL_REVISION", CURRENT_FUNCTION); testOk(header._flags == (int8_t)((EPICS_BYTE_ORDER == EPICS_ENDIAN_BIG ? 0x80 : 0x00) | 0x01), "%s: header._flags == 0x(0|8)1", CURRENT_FUNCTION); testOk(header._command == (int8_t)0x23, @@ -1537,8 +1537,8 @@ private: // app, no payload header = codec._receivedAppMessages[0]; - testOk(header._version == PVA_VERSION, - "%s: header._version == PVA_VERSION", CURRENT_FUNCTION); + testOk(header._version == PVA_CLIENT_PROTOCOL_REVISION, + "%s: header._version == PVA_CLIENT_PROTOCOL_REVISION", CURRENT_FUNCTION); testOk(header._flags == (int8_t)0x00, "%s: header._flags == 0x00", CURRENT_FUNCTION); testOk(header._command == (int8_t)0x20, @@ -1549,8 +1549,8 @@ private: // control header = codec._receivedControlMessages[0]; - testOk(header._version == PVA_VERSION, - "%s: header._version == PVA_VERSION", CURRENT_FUNCTION); + testOk(header._version == PVA_CLIENT_PROTOCOL_REVISION, + "%s: header._version == PVA_CLIENT_PROTOCOL_REVISION", CURRENT_FUNCTION); testOk(header._flags == (int8_t)0x81, "%s: header._flags == 0x81", CURRENT_FUNCTION); testOk(header._command == (int8_t)0xEE, @@ -1878,7 +1878,7 @@ private: codec._disconnected = true; codec._readBuffer->put(PVA_MAGIC); - codec._readBuffer->put(PVA_VERSION); + codec._readBuffer->put(PVA_CLIENT_PROTOCOL_REVISION); codec._readBuffer->put((int8_t)0x01); codec._readBuffer->put((int8_t)0x23); codec._readBuffer->putInt(0x456789AB); @@ -1953,7 +1953,7 @@ private: // 1st codec._readBuffer->put(PVA_MAGIC); - codec._readBuffer->put(PVA_VERSION); + codec._readBuffer->put(PVA_CLIENT_PROTOCOL_REVISION); codec._readBuffer->put((int8_t)0x90); codec._readBuffer->put((int8_t)0x01); @@ -1971,7 +1971,7 @@ private: // 2nd codec._readBuffer->put(PVA_MAGIC); - codec._readBuffer->put(PVA_VERSION); + codec._readBuffer->put(PVA_CLIENT_PROTOCOL_REVISION); codec._readBuffer->put((int8_t)0xB0); codec._readBuffer->put((int8_t)0x01); @@ -1991,7 +1991,7 @@ private: // 3rd codec._readBuffer->put(PVA_MAGIC); - codec._readBuffer->put(PVA_VERSION); + codec._readBuffer->put(PVA_CLIENT_PROTOCOL_REVISION); codec._readBuffer->put((int8_t)0xA0); codec._readBuffer->put((int8_t)0x01); @@ -2156,8 +2156,8 @@ private: // app, no payload PVAMessage header = codec._receivedAppMessages[0]; - testOk(header._version == PVA_VERSION, - "%s: header._version == PVA_VERSION", CURRENT_FUNCTION); + testOk(header._version == PVA_CLIENT_PROTOCOL_REVISION, + "%s: header._version == PVA_CLIENT_PROTOCOL_REVISION", CURRENT_FUNCTION); testOk(header._flags == (int8_t)((EPICS_BYTE_ORDER == EPICS_ENDIAN_BIG ? 0x80 : 0x00) | 0x00), "%s: header._flags == 0x(0|8)0", CURRENT_FUNCTION); testOk(header._command == (int8_t)0x20, @@ -2168,8 +2168,8 @@ private: // control header = codec._receivedControlMessages[0]; - testOk(header._version == PVA_VERSION, - "%s: header._version == PVA_VERSION", CURRENT_FUNCTION); + testOk(header._version == PVA_CLIENT_PROTOCOL_REVISION, + "%s: header._version == PVA_CLIENT_PROTOCOL_REVISION", CURRENT_FUNCTION); testOk(header._flags == (int8_t)((EPICS_BYTE_ORDER == EPICS_ENDIAN_BIG ? 0x80 : 0x00) | 0x01), "%s: header._flags == 0x(0|8)1", CURRENT_FUNCTION); testOk(header._command == (int8_t)0xEE, @@ -2293,8 +2293,8 @@ private: // app, no payload PVAMessage header = codec._receivedAppMessages[0]; - testOk(header._version == PVA_VERSION, - "%s: header._version == PVA_VERSION", CURRENT_FUNCTION); + testOk(header._version == PVA_CLIENT_PROTOCOL_REVISION, + "%s: header._version == PVA_CLIENT_PROTOCOL_REVISION", CURRENT_FUNCTION); testOk(header._flags == (int8_t)((EPICS_BYTE_ORDER == EPICS_ENDIAN_BIG ? 0x80 : 0x00) | 0x00), "%s: header._flags == 0x(0|8)0", CURRENT_FUNCTION); testOk(header._command == 0x20, @@ -2306,8 +2306,8 @@ private: // control header = codec._receivedControlMessages[0]; - testOk(header._version == PVA_VERSION, - "%s: header._version == PVA_VERSION", CURRENT_FUNCTION); + testOk(header._version == PVA_CLIENT_PROTOCOL_REVISION, + "%s: header._version == PVA_CLIENT_PROTOCOL_REVISION", CURRENT_FUNCTION); testOk(header._flags == (int8_t)((EPICS_BYTE_ORDER == EPICS_ENDIAN_BIG ? 0x80 : 0x00) | 0x01), "%s: header._flags == 0x(0|8)1", CURRENT_FUNCTION); testOk(header._command == (int8_t)0xEE, @@ -2363,8 +2363,8 @@ private: header = codec._receivedControlMessages[1]; - testOk(header._version == PVA_VERSION, - "%s: header._version == PVA_VERSION", CURRENT_FUNCTION); + testOk(header._version == PVA_CLIENT_PROTOCOL_REVISION, + "%s: header._version == PVA_CLIENT_PROTOCOL_REVISION", CURRENT_FUNCTION); testOk(header._flags == (int8_t)((EPICS_BYTE_ORDER == EPICS_ENDIAN_BIG ? 0x80 : 0x00) | 0x01), "%s: header._flags == 0x(0|8)1", CURRENT_FUNCTION); testOk(header._command == (int8_t)0xEE, @@ -2443,8 +2443,8 @@ private: // app PVAMessage header = codec._receivedAppMessages[0]; - testOk(header._version == PVA_VERSION, - "%s: header._version == PVA_VERSION", CURRENT_FUNCTION); + testOk(header._version == PVA_CLIENT_PROTOCOL_REVISION, + "%s: header._version == PVA_CLIENT_PROTOCOL_REVISION", CURRENT_FUNCTION); testOk(header._flags == (int8_t)0x80, "%s: header._flags == 0x80", CURRENT_FUNCTION); testOk(header._command == (int8_t)0x12, @@ -2640,8 +2640,8 @@ private: // app PVAMessage header = codec._receivedAppMessages[0]; - testOk(header._version == PVA_VERSION, - "%s: header._version == PVA_VERSION", CURRENT_FUNCTION); + testOk(header._version == PVA_CLIENT_PROTOCOL_REVISION, + "%s: header._version == PVA_CLIENT_PROTOCOL_REVISION", CURRENT_FUNCTION); testOk(header._flags == (int8_t)((EPICS_BYTE_ORDER == EPICS_ENDIAN_BIG ? 0x80 : 0x00) | 0x10), "%s: header._flags == (int8_t)(0x(0|8)0 | 0x10)", CURRENT_FUNCTION); From 0f26f39b5b2b281cc6ee08c16ab30d7acb73ff7e Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Mon, 20 May 2019 19:23:05 -0700 Subject: [PATCH 06/17] more de-virt getRevision() --- src/remote/pv/codec.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/remote/pv/codec.h b/src/remote/pv/codec.h index 6265d42..f3b4aaa 100644 --- a/src/remote/pv/codec.h +++ b/src/remote/pv/codec.h @@ -240,6 +240,12 @@ public: return _sendQueue.empty(); } + epics::pvData::int8 getRevision() const { + epicsGuard G(_mutex); + int8_t myver = _clientServerFlag ? PVA_SERVER_PROTOCOL_REVISION : PVA_CLIENT_PROTOCOL_REVISION; + return myver < _version ? myver : _version; + } + protected: virtual void sendBufferFull(int tries) = 0; @@ -365,12 +371,6 @@ public: return _socketName; } - epics::pvData::int8 getRevision() const { - epicsGuard G(_mutex); - int8_t myver = _clientServerFlag ? PVA_SERVER_PROTOCOL_REVISION : PVA_CLIENT_PROTOCOL_REVISION; - return myver < _version ? myver : _version; - } - virtual std::size_t getReceiveBufferSize() const OVERRIDE FINAL { return _socketBuffer.getSize(); From a1af3c2c8e65e5f36d62aea20713a9da0fd3a92e Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Thu, 16 May 2019 19:11:16 -0700 Subject: [PATCH 07/17] echo content --- src/server/pv/responseHandlers.h | 11 +++++++---- src/server/responseHandlers.cpp | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/server/pv/responseHandlers.h b/src/server/pv/responseHandlers.h index 3299cac..0db5615 100644 --- a/src/server/pv/responseHandlers.h +++ b/src/server/pv/responseHandlers.h @@ -93,20 +93,23 @@ public: class EchoTransportSender : public TransportSender { public: - EchoTransportSender(osiSockAddr* echoFrom) { + EchoTransportSender(osiSockAddr* echoFrom, size_t payloadSize, epics::pvData::ByteBuffer& payloadBuffer) { memcpy(&_echoFrom, echoFrom, sizeof(osiSockAddr)); + toEcho.resize(payloadSize); + memcpy(&toEcho[0], payloadBuffer.getBuffer(), payloadSize); } virtual ~EchoTransportSender() {} - virtual void send(epics::pvData::ByteBuffer* /*buffer*/, TransportSendControl* control) OVERRIDE FINAL { - control->startMessage(CMD_ECHO, 0); + virtual void send(epics::pvData::ByteBuffer* buffer, TransportSendControl* control) OVERRIDE FINAL { + control->startMessage(CMD_ECHO, toEcho.size(), toEcho.size()); control->setRecipient(_echoFrom); - // TODO content + buffer->putArray(&toEcho[0], toEcho.size()); } private: osiSockAddr _echoFrom; + std::vector toEcho; }; /****************************************************************************************/ diff --git a/src/server/responseHandlers.cpp b/src/server/responseHandlers.cpp index f0dd766..e115504 100644 --- a/src/server/responseHandlers.cpp +++ b/src/server/responseHandlers.cpp @@ -228,7 +228,7 @@ void ServerEchoHandler::handleResponse(osiSockAddr* responseFrom, transport, version, command, payloadSize, payloadBuffer); // send back - TransportSender::shared_pointer echoReply(new EchoTransportSender(responseFrom)); + TransportSender::shared_pointer echoReply(new EchoTransportSender(responseFrom, payloadSize, *payloadBuffer)); transport->enqueueSendRequest(echoReply); } From 79e73ab9662221fda73402c64ae544910d3b9cd6 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Mon, 20 May 2019 19:29:13 -0700 Subject: [PATCH 08/17] AbstractCodec cleanup --- src/remote/codec.cpp | 7 ++----- src/remote/pv/codec.h | 3 +-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/remote/codec.cpp b/src/remote/codec.cpp index 19d5975..424b4db 100644 --- a/src/remote/codec.cpp +++ b/src/remote/codec.cpp @@ -94,7 +94,7 @@ AbstractCodec::AbstractCodec( _remoteTransportSocketReceiveBufferSize(MAX_TCP_RECV), _totalBytesSent(0), _senderThread(0), _writeMode(PROCESS_SEND_QUEUE), - _writeOpReady(false),_lowLatency(false), + _writeOpReady(false), _socketBuffer(bufSizeSelect(receiveBufferSize)), _sendBuffer(bufSizeSelect(sendBufferSize)), //PRIVATE @@ -920,10 +920,7 @@ void AbstractCodec::enqueueSendRequest( processSender(sender); if (_sendBuffer.getPosition() > 0) { - if (_lowLatency) - flush(true); - else - scheduleSend(); + scheduleSend(); } } else diff --git a/src/remote/pv/codec.h b/src/remote/pv/codec.h index f3b4aaa..3772e8f 100644 --- a/src/remote/pv/codec.h +++ b/src/remote/pv/codec.h @@ -265,7 +265,6 @@ protected: epicsThreadId _senderThread; WriteMode _writeMode; bool _writeOpReady; - bool _lowLatency; epics::pvData::ByteBuffer _socketBuffer; epics::pvData::ByteBuffer _sendBuffer; @@ -296,7 +295,7 @@ private: epics::pvData::int8 _byteOrderFlag; protected: - epics::pvData::int8 _clientServerFlag; + const epics::pvData::int8 _clientServerFlag; private: const size_t _socketSendBufferSize; From 111a3dde86176277c9fbc60a1b401d908b8b7b24 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Mon, 20 May 2019 19:35:03 -0700 Subject: [PATCH 09/17] RX timeout Enable idle timeout if both peers have version>=2. --- src/remote/codec.cpp | 75 ++++++++++++++++++++++++++++++++++--------- src/remote/pv/codec.h | 3 ++ 2 files changed, 63 insertions(+), 15 deletions(-) diff --git a/src/remote/codec.cpp b/src/remote/codec.cpp index 424b4db..bf72803 100644 --- a/src/remote/codec.cpp +++ b/src/remote/codec.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -147,7 +148,12 @@ void AbstractCodec::processHeader() { int8_t magicCode = _socketBuffer.getByte(); // version - _version = _socketBuffer.getByte(); + int8_t ver = _socketBuffer.getByte(); + if(_version!=ver) { + // enable timeout if both ends support + _version = ver; + setRxTimeout(getRevision()>1); + } // flags _flags = _socketBuffer.getByte(); @@ -1115,6 +1121,10 @@ void BlockingTCPTransportCodec::receiveThread() */ Transport::shared_pointer ptr(this->shared_from_this()); + // initially enable timeout for all clients to weed out + // impersonators (security scanners?) + setRxTimeout(true); + while (this->isOpen()) { try { @@ -1166,6 +1176,27 @@ void BlockingTCPTransportCodec::sendThread() _sendQueue.clear(); } +void BlockingTCPTransportCodec::setRxTimeout(bool ena) +{ + double timeout = !ena ? 0.0 : std::max(0.0, _context->getConfiguration()->getPropertyAsDouble("EPICS_PVA_CONN_TMO", 30.0)); +#ifdef _WIN32 + DWORD timo = DWORD(timeout*1000); // in milliseconds +#else + timeval timo; + timo.tv_sec = unsigned(timeout); + timo.tv_usec = (timeout-timo.tv_sec)*1e6; +#endif + + int ret = setsockopt(_channel, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timo, sizeof(timo)); + if(ret==-1) { + int err = SOCKERRNO; + static int lasterr; + if(err!=lasterr) { + errlogPrintf("%s: Unable to set RX timeout: %d\n", _socketName.c_str(), err); + lasterr = err; + } + } +} void BlockingTCPTransportCodec::sendBufferFull(int tries) { // TODO constants @@ -1285,21 +1316,35 @@ int BlockingTCPTransportCodec::read(epics::pvData::ByteBuffer* dst) { // NOTE: do not log here, you might override SOCKERRNO relevant to recv() operation above - if(unlikely(bytesRead<=0)) { - - if (bytesRead<0) - { - int socketError = SOCKERRNO; - - // TODO SOCK_ENOBUFS, for read? - // interrupted or timeout - if (socketError == SOCK_EINTR || - socketError == EAGAIN || - socketError == SOCK_EWOULDBLOCK) - continue; - } - + if(unlikely(bytesRead==0)) { return -1; // 0 means connection loss for blocking transport, notify codec by returning -1 + + } else if(unlikely(bytesRead<0)) { + int err = SOCKERRNO; + + if(err==SOCK_EINTR) { + // interrupted by signal. Retry + continue; + + } else if(err==SOCK_EWOULDBLOCK || err==EAGAIN || err==SOCK_EINPROGRESS + || err==SOCK_ETIMEDOUT + || err==SOCK_ECONNABORTED || err==SOCK_ECONNRESET + ) { + // different ways of saying timeout. + // Linux: EAGAIN or EWOULDBLOCK, or EINPROGRESS + // WIN32: WSAETIMEDOUT + // others that RSRV checks for, but may not need to, ECONNABORTED, ECONNRESET + + // Note: with windows, after ETIMEOUT leaves the socket in an undefined state. + // so it must be closed. (cf. SO_RCVTIMEO) + + return -1; + + } else { + // some other (fatal) error + errlogPrintf("%s : Connection closed with RX socket error %d\n", _socketName.c_str(), err); + return -1; + } } dst->setPosition(dst->getPosition() + bytesRead); diff --git a/src/remote/pv/codec.h b/src/remote/pv/codec.h index 3772e8f..4807337 100644 --- a/src/remote/pv/codec.h +++ b/src/remote/pv/codec.h @@ -252,6 +252,7 @@ protected: void send(epics::pvData::ByteBuffer *buffer); void flushSendBuffer(); + virtual void setRxTimeout(bool ena) {} ReadMode _readMode; int8_t _version; @@ -436,6 +437,8 @@ private: void sendThread(); protected: + virtual void setRxTimeout(bool ena) OVERRIDE FINAL; + virtual void sendBufferFull(int tries) OVERRIDE FINAL; /** From 8d18b4ca3d75523f967f0a12ec0809a4e9f0279a Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Mon, 20 May 2019 16:50:53 -0700 Subject: [PATCH 10/17] PVA server protocol v2 Now with idle timeout! --- src/pva/pv/pvaConstants.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pva/pv/pvaConstants.h b/src/pva/pv/pvaConstants.h index e16fd5e..2ef9635 100644 --- a/src/pva/pv/pvaConstants.h +++ b/src/pva/pv/pvaConstants.h @@ -28,7 +28,7 @@ namespace pvAccess { /** PVA protocol magic number */ const epics::pvData::int8 PVA_MAGIC = static_cast(0xCA); -const epics::pvData::int8 PVA_SERVER_PROTOCOL_REVISION = 1; +const epics::pvData::int8 PVA_SERVER_PROTOCOL_REVISION = 2; const epics::pvData::int8 PVA_CLIENT_PROTOCOL_REVISION = 1; /** PVA protocol revision (implemented by this library). */ From 2da60b083e820f046cf89e392bb52cdb8dd07184 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Mon, 20 May 2019 21:00:43 -0700 Subject: [PATCH 11/17] Enable client sending of CMD_ECHO --- src/remote/codec.cpp | 54 ++++++++++++++++++++++--------------------- src/remote/pv/codec.h | 14 +++++------ 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/remote/codec.cpp b/src/remote/codec.cpp index bf72803..b8cc1f8 100644 --- a/src/remote/codec.cpp +++ b/src/remote/codec.cpp @@ -1696,24 +1696,26 @@ BlockingClientTCPTransportCodec::BlockingClientTCPTransportCodec( int16_t priority ) : BlockingTCPTransportCodec(false, context, channel, responseHandler, sendBufferSize, receiveBufferSize, priority), - _connectionTimeout(heartbeatInterval*1000), + _connectionTimeout(heartbeatInterval), _unresponsiveTransport(false), - _verifyOrEcho(true) + _verifyOrEcho(true), + sendQueued(true) // don't start sending echo until after auth complete { // initialize owners list, send queue acquire(client); // use immediate for clients //setFlushStrategy(DELAYED); - - // setup connection timeout timer (watchdog) - moved to start() method - epicsTimeGetCurrent(&_aliveTimestamp); } void BlockingClientTCPTransportCodec::start() { TimerCallbackPtr tcb = std::tr1::dynamic_pointer_cast(shared_from_this()); - _context->getTimer()->schedulePeriodic(tcb, _connectionTimeout, _connectionTimeout); + // add some randomness to our timer phase + double R = float(rand())/RAND_MAX; // [0, 1] + // shape a bit + R = R*0.5 + 0.5; // [0.5, 1.0] + _context->getTimer()->schedulePeriodic(tcb, _connectionTimeout/2.0*R, _connectionTimeout/2.0); BlockingTCPTransportCodec::start(); } @@ -1728,24 +1730,16 @@ BlockingClientTCPTransportCodec::~BlockingClientTCPTransportCodec() { -void BlockingClientTCPTransportCodec::callback() { - epicsTimeStamp currentTime; - epicsTimeGetCurrent(¤tTime); - - _mutex.lock(); - // no exception expected here - double diff = epicsTimeDiffInSeconds(¤tTime, &_aliveTimestamp); - _mutex.unlock(); - - if(diff>((3*_connectionTimeout)/2)) { - unresponsiveTransport(); - } - // use some k (3/4) to handle "jitter" - else if(diff>=((3*_connectionTimeout)/4)) { - // send echo - TransportSender::shared_pointer transportSender = std::tr1::dynamic_pointer_cast(shared_from_this()); - enqueueSendRequest(transportSender); +void BlockingClientTCPTransportCodec::callback() +{ + { + Guard G(_mutex); + if(sendQueued) return; + sendQueued = true; } + // send echo + TransportSender::shared_pointer transportSender = std::tr1::dynamic_pointer_cast(shared_from_this()); + enqueueSendRequest(transportSender); } #define EXCEPTION_GUARD(code) try { code; } \ @@ -1842,8 +1836,9 @@ void BlockingClientTCPTransportCodec::release(pvAccessID clientID) { } void BlockingClientTCPTransportCodec::aliveNotification() { + // TODO: dead code Lock guard(_mutex); - epicsTimeGetCurrent(&_aliveTimestamp); + //epicsTimeGetCurrent(&_aliveTimestamp); if(_unresponsiveTransport) responsiveTransport(); } @@ -1879,10 +1874,17 @@ void BlockingClientTCPTransportCodec::changedTransport() { } void BlockingClientTCPTransportCodec::send(ByteBuffer* buffer, - TransportSendControl* control) { - if(_verifyOrEcho) { + TransportSendControl* control) +{ + bool voe; + { + Guard G(_mutex); + sendQueued = false; + voe = _verifyOrEcho; _verifyOrEcho = false; + } + if(voe) { /* * send verification response message */ diff --git a/src/remote/pv/codec.h b/src/remote/pv/codec.h index 4807337..245f227 100644 --- a/src/remote/pv/codec.h +++ b/src/remote/pv/codec.h @@ -335,7 +335,7 @@ public: virtual void waitJoin() OVERRIDE FINAL; virtual bool terminated() OVERRIDE FINAL; virtual bool isOpen() OVERRIDE FINAL; - void start(); + virtual void start(); virtual int read(epics::pvData::ByteBuffer* dst) OVERRIDE FINAL; virtual int write(epics::pvData::ByteBuffer* src) OVERRIDE FINAL; @@ -646,7 +646,7 @@ public: public: - void start(); + virtual void start() OVERRIDE FINAL; virtual ~BlockingClientTCPTransportCodec() OVERRIDE FINAL; @@ -689,20 +689,18 @@ private: /** * Connection timeout (no-traffic) flag. */ - double _connectionTimeout; + const double _connectionTimeout; /** * Unresponsive transport flag. */ bool _unresponsiveTransport; - /** - * Timestamp of last "live" event on this transport. - */ - epicsTimeStamp _aliveTimestamp; - bool _verifyOrEcho; + // are we queued to send verify or echo? + bool sendQueued; + /** * Unresponsive transport notify. */ From c9bd214f7ce5790235eb9ed40352f03b6b951a31 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Mon, 20 May 2019 21:33:28 -0700 Subject: [PATCH 12/17] client proto v2 --- src/pva/pv/pvaConstants.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pva/pv/pvaConstants.h b/src/pva/pv/pvaConstants.h index 2ef9635..b4423e9 100644 --- a/src/pva/pv/pvaConstants.h +++ b/src/pva/pv/pvaConstants.h @@ -29,7 +29,7 @@ namespace pvAccess { const epics::pvData::int8 PVA_MAGIC = static_cast(0xCA); const epics::pvData::int8 PVA_SERVER_PROTOCOL_REVISION = 2; -const epics::pvData::int8 PVA_CLIENT_PROTOCOL_REVISION = 1; +const epics::pvData::int8 PVA_CLIENT_PROTOCOL_REVISION = 2; /** PVA protocol revision (implemented by this library). */ const epics::pvData::int8 PVA_PROTOCOL_REVISION EPICS_DEPRECATED = 1; From a6e7d7f5fcbd568380178ccd7d27c6d616eaaee6 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Mon, 20 May 2019 22:29:01 -0700 Subject: [PATCH 13/17] Remove dead code aliveNotification() and unresponsiveTransport() never called. Remove these, and code only referenced through these methods. --- TODO | 1 - src/remote/codec.cpp | 51 ------------------------- src/remote/pv/blockingUDP.h | 4 -- src/remote/pv/codec.h | 21 ---------- src/remote/pv/remote.h | 5 --- src/remoteClient/clientContextImpl.cpp | 36 ----------------- src/remoteClient/pv/clientContextImpl.h | 3 -- testApp/remote/testCodec.cpp | 2 - 8 files changed, 123 deletions(-) diff --git a/TODO b/TODO index 7c82d7e..2e504d4 100644 --- a/TODO +++ b/TODO @@ -6,6 +6,5 @@ - improve searching of channel with server address specified -- void transportUnresponsive() is not implemented (also in Java) - complete authNZ (callback on right change) - request event on disconnect/destroy, etc.? diff --git a/src/remote/codec.cpp b/src/remote/codec.cpp index b8cc1f8..94f0730 100644 --- a/src/remote/codec.cpp +++ b/src/remote/codec.cpp @@ -1697,7 +1697,6 @@ BlockingClientTCPTransportCodec::BlockingClientTCPTransportCodec( BlockingTCPTransportCodec(false, context, channel, responseHandler, sendBufferSize, receiveBufferSize, priority), _connectionTimeout(heartbeatInterval), - _unresponsiveTransport(false), _verifyOrEcho(true), sendQueued(true) // don't start sending echo until after auth complete { @@ -1746,22 +1745,6 @@ void BlockingClientTCPTransportCodec::callback() catch (std::exception &e) { LOG(logLevelError, "Unhandled exception caught from code at %s:%d: %s", __FILE__, __LINE__, e.what()); } \ catch (...) { LOG(logLevelError, "Unhandled exception caught from code at %s:%d.", __FILE__, __LINE__); } -void BlockingClientTCPTransportCodec::unresponsiveTransport() { - Lock lock(_mutex); - if(!_unresponsiveTransport) { - _unresponsiveTransport = true; - - TransportClientMap_t::iterator it = _owners.begin(); - for(; it!=_owners.end(); it++) { - ClientChannelImpl::shared_pointer client = it->second.lock(); - if (client) - { - EXCEPTION_GUARD(client->transportUnresponsive()); - } - } - } -} - bool BlockingClientTCPTransportCodec::acquire(ClientChannelImpl::shared_pointer const & client) { Lock lock(_mutex); if(isClosed()) return false; @@ -1835,42 +1818,8 @@ void BlockingClientTCPTransportCodec::release(pvAccessID clientID) { } } -void BlockingClientTCPTransportCodec::aliveNotification() { - // TODO: dead code - Lock guard(_mutex); - //epicsTimeGetCurrent(&_aliveTimestamp); - if(_unresponsiveTransport) responsiveTransport(); -} - -void BlockingClientTCPTransportCodec::responsiveTransport() { - Lock lock(_mutex); - if(_unresponsiveTransport) { - _unresponsiveTransport = false; - - Transport::shared_pointer thisSharedPtr = shared_from_this(); - TransportClientMap_t::iterator it = _owners.begin(); - for(; it!=_owners.end(); it++) { - ClientChannelImpl::shared_pointer client = it->second.lock(); - if (client) - { - EXCEPTION_GUARD(client->transportResponsive(thisSharedPtr)); - } - } - } -} - void BlockingClientTCPTransportCodec::changedTransport() { _outgoingIR.reset(); - - Lock lock(_mutex); - TransportClientMap_t::iterator it = _owners.begin(); - for(; it!=_owners.end(); it++) { - ClientChannelImpl::shared_pointer client = it->second.lock(); - if (client) - { - EXCEPTION_GUARD(client->transportChanged()); - } - } } void BlockingClientTCPTransportCodec::send(ByteBuffer* buffer, diff --git a/src/remote/pv/blockingUDP.h b/src/remote/pv/blockingUDP.h index e7064a4..6a93b3c 100644 --- a/src/remote/pv/blockingUDP.h +++ b/src/remote/pv/blockingUDP.h @@ -97,10 +97,6 @@ public: // noop for UDP (limited by 64k; MAX_UDP_SEND for PVA) } - virtual void aliveNotification() OVERRIDE FINAL { - // noop - } - virtual void changedTransport() OVERRIDE FINAL { // noop } diff --git a/src/remote/pv/codec.h b/src/remote/pv/codec.h index 245f227..5ba69c4 100644 --- a/src/remote/pv/codec.h +++ b/src/remote/pv/codec.h @@ -558,10 +558,6 @@ public: BlockingTCPTransportCodec::verified(status); } - virtual void aliveNotification() OVERRIDE FINAL { - // noop on server-side - } - void authNZInitialize(const std::string& securityPluginName, const epics::pvData::PVStructure::shared_pointer& data); @@ -662,8 +658,6 @@ public: virtual void changedTransport() OVERRIDE FINAL; - virtual void aliveNotification() OVERRIDE FINAL; - virtual void send(epics::pvData::ByteBuffer* buffer, TransportSendControl* control) OVERRIDE FINAL; @@ -691,30 +685,15 @@ private: */ const double _connectionTimeout; - /** - * Unresponsive transport flag. - */ - bool _unresponsiveTransport; - bool _verifyOrEcho; // are we queued to send verify or echo? bool sendQueued; - /** - * Unresponsive transport notify. - */ - void unresponsiveTransport(); - /** * Notifies clients about disconnect. */ void closedNotifyClients(); - - /** - * Responsive transport notify. - */ - void responsiveTransport(); }; } diff --git a/src/remote/pv/remote.h b/src/remote/pv/remote.h index b096008..e807c35 100644 --- a/src/remote/pv/remote.h +++ b/src/remote/pv/remote.h @@ -250,11 +250,6 @@ public: */ virtual bool verify(epics::pvData::int32 timeoutMs) = 0; - /** - * Notification transport that is still alive. - */ - virtual void aliveNotification() = 0; - /** * Close transport. */ diff --git a/src/remoteClient/clientContextImpl.cpp b/src/remoteClient/clientContextImpl.cpp index 57f2237..45d0b70 100644 --- a/src/remoteClient/clientContextImpl.cpp +++ b/src/remoteClient/clientContextImpl.cpp @@ -3675,13 +3675,6 @@ public: reportChannelStateChange(); } - virtual void transportChanged() OVERRIDE FINAL { -// initiateSearch(); - // TODO - // this will be called immediately after reconnect... bad... - - } - virtual Transport::shared_pointer checkAndGetTransport() OVERRIDE FINAL { Lock guard(m_channelMutex); @@ -3711,35 +3704,6 @@ public: return m_transport; } - virtual void transportResponsive(Transport::shared_pointer const & /*transport*/) OVERRIDE FINAL { - Lock guard(m_channelMutex); - if (m_connectionState == DISCONNECTED) - { - updateSubscriptions(); - - // reconnect using existing IDs, data - connectionCompleted(m_serverChannelID/*, accessRights*/); - } - } - - virtual void transportUnresponsive() OVERRIDE FINAL { - /* - { - Lock guard(m_channelMutex); - if (m_connectionState == CONNECTED) - { - // TODO 2 types of disconnected state - distinguish them otherwise disconnect will handle connection loss right - setConnectionState(DISCONNECTED); - - // ... PVA notifies also w/ no access rights callback, although access right are not changed - } - } - - // should be called without any lock hold - reportChannelStateChange(); - */ - } - /** * Set connection state and if changed, notifies listeners. * @param newState state to set. diff --git a/src/remoteClient/pv/clientContextImpl.h b/src/remoteClient/pv/clientContextImpl.h index a003d65..7c04f69 100644 --- a/src/remoteClient/pv/clientContextImpl.h +++ b/src/remoteClient/pv/clientContextImpl.h @@ -53,10 +53,7 @@ public: virtual Transport::shared_pointer checkAndGetTransport() = 0; virtual Transport::shared_pointer checkDestroyedAndGetTransport() = 0; virtual Transport::shared_pointer getTransport() = 0; - virtual void transportUnresponsive() =0; - virtual void transportChanged() =0; virtual void transportClosed() =0; - virtual void transportResponsive(Transport::shared_pointer const & /*transport*/) =0; static epics::pvData::Status channelDestroyed; static epics::pvData::Status channelDisconnected; diff --git a/testApp/remote/testCodec.cpp b/testApp/remote/testCodec.cpp index ba8447d..0b077be 100644 --- a/testApp/remote/testCodec.cpp +++ b/testApp/remote/testCodec.cpp @@ -382,8 +382,6 @@ public: void verified(epics::pvData::Status const &) {} - void aliveNotification() {} - void authNZMessage(epics::pvData::PVStructure::shared_pointer const & data) {} From 9e05b29f359b641374a3fa68b7c0e4b1ffee2ba9 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Mon, 20 May 2019 22:37:15 -0700 Subject: [PATCH 14/17] Don't clear client _outgoingIR on beacon anomaly No reason to do this, especially w/o locking. Outgoing used by a TCP send thread, beacon anomaly handling on UDP receive thread. Probably means that anomaly handling never happens... --- src/remote/codec.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/remote/codec.cpp b/src/remote/codec.cpp index 94f0730..ae7d099 100644 --- a/src/remote/codec.cpp +++ b/src/remote/codec.cpp @@ -1819,7 +1819,6 @@ void BlockingClientTCPTransportCodec::release(pvAccessID clientID) { } void BlockingClientTCPTransportCodec::changedTransport() { - _outgoingIR.reset(); } void BlockingClientTCPTransportCodec::send(ByteBuffer* buffer, From 6dd1346acee911bf684c750e0aaac10929fdb13b Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Mon, 20 May 2019 22:51:38 -0700 Subject: [PATCH 15/17] further dead code --- src/remote/beaconHandler.cpp | 17 ++--------------- src/remote/codec.cpp | 3 --- src/remote/pv/beaconHandler.h | 4 ---- src/remote/pv/blockingUDP.h | 4 ---- src/remote/pv/codec.h | 4 ---- src/remote/pv/remote.h | 5 ----- testApp/remote/testCodec.cpp | 2 -- 7 files changed, 2 insertions(+), 37 deletions(-) diff --git a/src/remote/beaconHandler.cpp b/src/remote/beaconHandler.cpp index 619c4de..249ebd9 100644 --- a/src/remote/beaconHandler.cpp +++ b/src/remote/beaconHandler.cpp @@ -37,8 +37,8 @@ void BeaconHandler::beaconNotify(osiSockAddr* /*from*/, int8 remoteTransportRevi PVFieldPtr /*data*/) { bool networkChanged = updateBeacon(remoteTransportRevision, timestamp, guid, sequentalID, changeCount); - if (networkChanged) - changedTransport(); + // TODO: reduce search timers + (void)networkChanged; } bool BeaconHandler::updateBeacon(int8 /*remoteTransportRevision*/, TimeStamp* /*timestamp*/, @@ -83,19 +83,6 @@ bool BeaconHandler::updateBeacon(int8 /*remoteTransportRevision*/, TimeStamp* /* return false; } -void BeaconHandler::changedTransport() -{ - TransportRegistry::transportVector_t transports; - _context.lock()->getTransportRegistry()->toArray(transports, &_responseFrom); - - // notify all - for (TransportRegistry::transportVector_t::iterator iter(transports.begin()), end(transports.end()); - iter != end; iter++) - { - (*iter)->changedTransport(); - } -} - } } diff --git a/src/remote/codec.cpp b/src/remote/codec.cpp index ae7d099..cfc0809 100644 --- a/src/remote/codec.cpp +++ b/src/remote/codec.cpp @@ -1818,9 +1818,6 @@ void BlockingClientTCPTransportCodec::release(pvAccessID clientID) { } } -void BlockingClientTCPTransportCodec::changedTransport() { -} - void BlockingClientTCPTransportCodec::send(ByteBuffer* buffer, TransportSendControl* control) { diff --git a/src/remote/pv/beaconHandler.h b/src/remote/pv/beaconHandler.h index b6c2bb8..dbaeccd 100644 --- a/src/remote/pv/beaconHandler.h +++ b/src/remote/pv/beaconHandler.h @@ -101,10 +101,6 @@ private: ServerGUID const &guid, epics::pvData::int16 sequentalID, epics::pvData::int16 changeCount); - /** - * Changed transport (server restarted) notify. - */ - void changedTransport(); }; } diff --git a/src/remote/pv/blockingUDP.h b/src/remote/pv/blockingUDP.h index 6a93b3c..5312c61 100644 --- a/src/remote/pv/blockingUDP.h +++ b/src/remote/pv/blockingUDP.h @@ -97,10 +97,6 @@ public: // noop for UDP (limited by 64k; MAX_UDP_SEND for PVA) } - virtual void changedTransport() OVERRIDE FINAL { - // noop - } - virtual bool verify(epics::pvData::int32 /*timeoutMs*/) OVERRIDE FINAL { // noop return true; diff --git a/src/remote/pv/codec.h b/src/remote/pv/codec.h index 5ba69c4..43e941d 100644 --- a/src/remote/pv/codec.h +++ b/src/remote/pv/codec.h @@ -519,8 +519,6 @@ public: virtual void release(pvAccessID /*clientId*/) OVERRIDE FINAL {} - virtual void changedTransport() OVERRIDE {} - pvAccessID preallocateChannelSID(); void depreallocateChannelSID(pvAccessID /*sid*/) {} @@ -656,8 +654,6 @@ public: virtual void release(pvAccessID clientId) OVERRIDE FINAL; - virtual void changedTransport() OVERRIDE FINAL; - virtual void send(epics::pvData::ByteBuffer* buffer, TransportSendControl* control) OVERRIDE FINAL; diff --git a/src/remote/pv/remote.h b/src/remote/pv/remote.h index e807c35..6521677 100644 --- a/src/remote/pv/remote.h +++ b/src/remote/pv/remote.h @@ -222,11 +222,6 @@ public: // TODO enum virtual void setByteOrder(int byteOrder) = 0; - /** - * Notification that transport has changed. - */ - virtual void changedTransport() = 0; - /** * Enqueue send request. * @param sender diff --git a/testApp/remote/testCodec.cpp b/testApp/remote/testCodec.cpp index 0b077be..8af85f2 100644 --- a/testApp/remote/testCodec.cpp +++ b/testApp/remote/testCodec.cpp @@ -372,8 +372,6 @@ public: void setRemoteTransportReceiveBufferSize( std::size_t remoteTransportReceiveBufferSize) {} - void changedTransport() {} - void flushSendQueue() { }; bool verify(epics::pvData::int32 timeoutMs) { From 5abfc10a828311a83dee7da43ff6a6ccd0130066 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Wed, 12 Jun 2019 13:21:27 -0700 Subject: [PATCH 16/17] really echo this time... --- src/server/pv/responseHandlers.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/pv/responseHandlers.h b/src/server/pv/responseHandlers.h index 0db5615..f090850 100644 --- a/src/server/pv/responseHandlers.h +++ b/src/server/pv/responseHandlers.h @@ -96,7 +96,7 @@ public: EchoTransportSender(osiSockAddr* echoFrom, size_t payloadSize, epics::pvData::ByteBuffer& payloadBuffer) { memcpy(&_echoFrom, echoFrom, sizeof(osiSockAddr)); toEcho.resize(payloadSize); - memcpy(&toEcho[0], payloadBuffer.getBuffer(), payloadSize); + payloadBuffer.getArray(&toEcho[0], payloadSize); } virtual ~EchoTransportSender() {} From 05bf0fc453a9ae4de9007fbe7ba7da128fef4538 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Thu, 13 Jun 2019 10:52:12 -0700 Subject: [PATCH 17/17] CAPlugin handle peer NULL data --- src/remote/security.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/remote/security.cpp b/src/remote/security.cpp index c19c8e2..5838028 100644 --- a/src/remote/security.cpp +++ b/src/remote/security.cpp @@ -95,9 +95,15 @@ struct CAPlugin : public pva::AuthenticationPlugin { std::tr1::shared_ptr sess(new SimpleSession(user)); // no init data if(server) { - peer->identified = true; - peer->account = data->getSubFieldT("user")->get(); - peer->aux = pvd::getPVDataCreate()->createPVStructure(data); // clone to ensure it won't be modified + pvd::PVString::shared_pointer user; + if(data) + user = data->getSubField("user"); + + if(user) { + peer->account = user->get(); + peer->identified = !peer->account.empty(); + peer->aux = pvd::getPVDataCreate()->createPVStructure(data); // clone to ensure it won't be modified + } control->authenticationCompleted(pvd::Status::Ok, peer); } return sess;