From 544fc6bd73e6d11ef09e120151a006a368c2f51c Mon Sep 17 00:00:00 2001 From: miha_vitorovic Date: Wed, 5 Jan 2011 09:20:51 +0100 Subject: [PATCH] Added NamedLockPattern to BlockingTCPConnector and resolved some warnings and compilation/linker errors. Reference to '__sync_add_and_fetch' and '__sync_sub_and_fetch' removed for now, since it is glibc version specific. --- pvAccessApp/remote/blockingTCP.h | 19 +++++++++++-- pvAccessApp/remote/blockingTCPConnector.cpp | 22 +++++++-------- pvAccessApp/remote/remote.h | 31 +++++++++++++++++---- pvAccessApp/utils/referenceCountingLock.cpp | 12 +++++--- 4 files changed, 61 insertions(+), 23 deletions(-) diff --git a/pvAccessApp/remote/blockingTCP.h b/pvAccessApp/remote/blockingTCP.h index 923a7b7..8e11405 100644 --- a/pvAccessApp/remote/blockingTCP.h +++ b/pvAccessApp/remote/blockingTCP.h @@ -14,6 +14,7 @@ #include "growingCircularBuffer.h" #include "transportRegistry.h" #include "introspectionRegistry.h" +#include "namedLockPattern.h" /* pvData */ #include @@ -473,6 +474,20 @@ namespace epics { void responsiveTransport(); }; + /** + * comparator for osiSockAddr* + */ + struct comp_osiSockAddrPtr + { + bool operator()(osiSockAddr const *a, osiSockAddr const *b) + { + if (a->sa.sa_family < b->sa.sa_family) return true; + if ((a->sa.sa_family == b->sa.sa_family) && (a->ia.sin_addr.s_addr < b->ia.sin_addr.s_addr )) return true; + if ((a->sa.sa_family == b->sa.sa_family) && (a->ia.sin_addr.s_addr == b->ia.sin_addr.s_addr ) && ( a->ia.sin_port < b->ia.sin_port )) return true; + return false; + } + }; + /** * Channel Access TCP connector. * @author Matej Sekoranja @@ -500,9 +515,9 @@ namespace epics { Context* _context; /** - * Context instance. + * named lock */ - //NamedLockPattern* _namedLocker; + NamedLockPattern* _namedLocker; /** * Receive buffer size. diff --git a/pvAccessApp/remote/blockingTCPConnector.cpp b/pvAccessApp/remote/blockingTCPConnector.cpp index 0779ea4..0c7e7f1 100644 --- a/pvAccessApp/remote/blockingTCPConnector.cpp +++ b/pvAccessApp/remote/blockingTCPConnector.cpp @@ -7,6 +7,7 @@ #include "blockingTCP.h" #include "remote.h" +#include "namedLockPattern.h" #include #include @@ -21,14 +22,14 @@ namespace epics { BlockingTCPConnector::BlockingTCPConnector(Context* context, int receiveBufferSize, float beaconInterval) : - _context(context), _receiveBufferSize(receiveBufferSize), - _beaconInterval(beaconInterval) - //TODO , _namedLocker(new NamedLockPattern()) - { + _context(context), _namedLocker(new NamedLockPattern< + const osiSockAddr*, comp_osiSockAddrPtr> ()), + _receiveBufferSize(receiveBufferSize), _beaconInterval( + beaconInterval) { } BlockingTCPConnector::~BlockingTCPConnector() { - // TODO delete _namedLocker; + delete _namedLocker; } SOCKET BlockingTCPConnector::tryConnect(osiSockAddr* address, int tries) { @@ -86,10 +87,8 @@ namespace epics { if(transport->acquire(client)) return transport; } - bool lockAcquired = true; - // TODO comment out - //bool lockAcquired = _namedLocker->acquireSynchronizationObject( - // address, LOCK_TIMEOUT); + bool lockAcquired = _namedLocker->acquireSynchronizationObject( + address, LOCK_TIMEOUT); if(lockAcquired) { try { // ... transport created during waiting in lock @@ -157,11 +156,10 @@ namespace epics { } catch(...) { // close socket, if open if(socket!=INVALID_SOCKET) epicsSocketDestroy(socket); - - // TODO namedLocker.releaseSynchronizationObject(address); - + _namedLocker->releaseSynchronizationObject(address); throw; } + _namedLocker->releaseSynchronizationObject(address); } else { ostringstream temp; diff --git a/pvAccessApp/remote/remote.h b/pvAccessApp/remote/remote.h index e192b52..3dd3720 100644 --- a/pvAccessApp/remote/remote.h +++ b/pvAccessApp/remote/remote.h @@ -46,6 +46,9 @@ namespace epics { */ class TransportSendControl : public epics::pvData::SerializableControl { public: + virtual ~TransportSendControl() { + } + virtual void startMessage(int8 command, int ensureCapacity) =0; virtual void endMessage() =0; @@ -61,6 +64,8 @@ namespace epics { */ class TransportSender { public: + virtual ~TransportSender() {} + /** * Called by transport. * By this call transport gives callee ownership over the buffer. @@ -69,8 +74,7 @@ namespace epics { * of this method. * NOTE: these limitations allows efficient implementation. */ - virtual void - send(epics::pvData::ByteBuffer* buffer, + virtual void send(epics::pvData::ByteBuffer* buffer, TransportSendControl* control) =0; virtual void lock() =0; @@ -213,6 +217,8 @@ namespace epics { */ class ResponseHandler { public: + virtual ~ResponseHandler() {} + /** * Handle response. * @param[in] responseFrom remote address of the responder, null if unknown. @@ -224,9 +230,10 @@ namespace epics { * Code must not manipulate buffer. */ virtual void - handleResponse(osiSockAddr* responseFrom, Transport* transport, - int8 version, int8 command, int payloadSize, - epics::pvData::ByteBuffer* payloadBuffer) =0; + handleResponse(osiSockAddr* responseFrom, + Transport* transport, int8 version, int8 command, + int payloadSize, + epics::pvData::ByteBuffer* payloadBuffer) =0; }; /** @@ -341,6 +348,8 @@ namespace epics { */ class TransportClient { public: + virtual ~TransportClient(); + /** * Notification of unresponsive transport (e.g. no heartbeat detected) . */ @@ -372,6 +381,9 @@ namespace epics { */ class Connector { public: + virtual ~Connector() { + } + /** * Connect. * @param[in] client client requesting connection (transport). @@ -390,6 +402,8 @@ namespace epics { class Context { public: + virtual ~Context() { + } /** * Get timer. * @return timer. @@ -410,6 +424,8 @@ namespace epics { */ class ReferenceCountingTransport { public: + virtual ~ReferenceCountingTransport() {} + /** * Acquires transport. * @param client client (channel) acquiring the transport @@ -426,6 +442,8 @@ namespace epics { class ServerChannel { public: + virtual ~ServerChannel() { + } /** * Get channel SID. * @return channel SID. @@ -446,6 +464,9 @@ namespace epics { */ class ChannelHostingTransport { public: + virtual ~ChannelHostingTransport() { + } + /** * Get security token. * @return security token, can be null. diff --git a/pvAccessApp/utils/referenceCountingLock.cpp b/pvAccessApp/utils/referenceCountingLock.cpp index 4a8b3fb..abd2250 100644 --- a/pvAccessApp/utils/referenceCountingLock.cpp +++ b/pvAccessApp/utils/referenceCountingLock.cpp @@ -66,15 +66,19 @@ void ReferenceCountingLock::release() int ReferenceCountingLock::increment() { //TODO does it really has to be atomic? - //return ++_references; - return __sync_add_and_fetch(&_references,1); + return ++_references; + // commented because linking depends on specific version of glibc library + // on i386 target + //return __sync_add_and_fetch(&_references,1); } int ReferenceCountingLock::decrement() { //TODO does it really has to be atomic? - //return --_references; - return __sync_sub_and_fetch(&_references,1); + return --_references; + // commented because linking depends on specific version of glibc library + // on i386 target + //return __sync_sub_and_fetch(&_references,1); } }}