/** * Copyright - See the COPYRIGHT that is included with this distribution. * pvAccessCPP is distributed subject to a Software License Agreement found * in file LICENSE that is included with this distribution. */ #ifndef BLOCKINGTCP_H_ #define BLOCKINGTCP_H_ #include #include #include #ifdef epicsExportSharedSymbols # define blockingTCPEpicsExportSharedSymbols # undef epicsExportSharedSymbols #endif #include #include #include #include #include #include #include #include #include #include #ifdef blockingTCPEpicsExportSharedSymbols # define epicsExportSharedSymbols # undef blockingTCPEpicsExportSharedSymbols #endif #include #include #include #include #include #include namespace epics { namespace pvAccess { /** * Channel Access TCP connector. * @author Matej Sekoranja * @version $Id: BlockingTCPConnector.java,v 1.1 2010/05/03 14:45:47 mrkraimer Exp $ */ class BlockingTCPConnector : public Connector { public: POINTER_DEFINITIONS(BlockingTCPConnector); BlockingTCPConnector(Context::shared_pointer const & context, int receiveBufferSize, float beaconInterval); virtual ~BlockingTCPConnector(); virtual Transport::shared_pointer connect(TransportClient::shared_pointer const & client, std::auto_ptr& responseHandler, osiSockAddr& address, epics::pvData::int8 transportRevision, epics::pvData::int16 priority); private: /** * Lock timeout */ static const int LOCK_TIMEOUT = 20*1000; // 20s /** * Context instance. */ Context::weak_pointer _context; /** * named lock */ NamedLockPattern _namedLocker; /** * Receive buffer size. */ int _receiveBufferSize; /** * Beacon interval. */ float _beaconInterval; /** * Tries to connect to the given address. * @param[in] address * @param[in] tries * @return the SOCKET * @throws IOException */ SOCKET tryConnect(osiSockAddr& address, int tries); }; class ResponseHandlerFactory { public: POINTER_DEFINITIONS(ResponseHandlerFactory); virtual ~ResponseHandlerFactory() {}; virtual std::auto_ptr createResponseHandler() = 0; }; /** * Channel Access Server TCP acceptor. * @author Matej Sekoranja * @version $Id: BlockingTCPAcceptor.java,v 1.1 2010/05/03 14:45:42 mrkraimer Exp $ */ class BlockingTCPAcceptor { public: POINTER_DEFINITIONS(BlockingTCPAcceptor); /** * @param context * @param port * @param receiveBufferSize * @throws PVAException */ BlockingTCPAcceptor(Context::shared_pointer const & context, ResponseHandlerFactory::shared_pointer const & responseHandlerFactory, int port, int receiveBufferSize); virtual ~BlockingTCPAcceptor(); void handleEvents(); /** * Bind socket address. * @return bind socket address, null if not binded. */ const osiSockAddr* getBindAddress() { return &_bindAddress; } /** * Destroy acceptor (stop listening). */ void destroy(); private: /** * Context instance. */ Context::shared_pointer _context; /** * ResponseHandler factory. */ ResponseHandlerFactory::shared_pointer _responseHandlerFactory; /** * Bind server socket address. */ osiSockAddr _bindAddress; /** * Server socket channel. */ SOCKET _serverSocketChannel; /** * Receive buffer size. */ int _receiveBufferSize; /** * Destroyed flag. */ bool _destroyed; epics::pvData::Mutex _mutex; epicsThreadId _threadId; /** * Initialize connection acception. * @return port where server is listening */ int initialize(unsigned short port); /** * Validate connection by sending a validation message request. * @return true on success. */ bool validateConnection(Transport::shared_pointer const & transport, const char* address); static void handleEventsRunner(void* param); }; } } #endif /* BLOCKINGTCP_H_ */