pvAccessCPP  7.1.6
blockingTCP.h
1 /**
2  * Copyright - See the COPYRIGHT that is included with this distribution.
3  * pvAccessCPP is distributed subject to a Software License Agreement found
4  * in file LICENSE that is included with this distribution.
5  */
6 
7 #ifndef BLOCKINGTCP_H_
8 #define BLOCKINGTCP_H_
9 
10 #include <set>
11 #include <map>
12 #include <deque>
13 
14 #ifdef epicsExportSharedSymbols
15 # define blockingTCPEpicsExportSharedSymbols
16 # undef epicsExportSharedSymbols
17 #endif
18 
19 #include <shareLib.h>
20 #include <osiSock.h>
21 #include <epicsTime.h>
22 #include <epicsThread.h>
23 
24 #include <pv/byteBuffer.h>
25 #include <pv/pvType.h>
26 #include <pv/lock.h>
27 #include <pv/timer.h>
28 #include <pv/event.h>
29 
30 #ifdef blockingTCPEpicsExportSharedSymbols
31 # define epicsExportSharedSymbols
32 # undef blockingTCPEpicsExportSharedSymbols
33 #endif
34 
35 #include <pv/pvaConstants.h>
36 #include <pv/remote.h>
37 #include <pv/transportRegistry.h>
38 #include <pv/introspectionRegistry.h>
39 #include <pv/inetAddressUtil.h>
40 
41 namespace epics {
42 namespace pvAccess {
43 
44 class ClientChannelImpl;
45 
46 /**
47  * Channel Access TCP connector.
48  * @author <a href="mailto:matej.sekoranjaATcosylab.com">Matej Sekoranja</a>
49  * @version $Id: BlockingTCPConnector.java,v 1.1 2010/05/03 14:45:47 mrkraimer Exp $
50  */
51 class BlockingTCPConnector {
52 public:
53  POINTER_DEFINITIONS(BlockingTCPConnector);
54 
55  BlockingTCPConnector(Context::shared_pointer const & context, int receiveBufferSize,
56  float beaconInterval);
57 
58  Transport::shared_pointer connect(std::tr1::shared_ptr<ClientChannelImpl> const & client,
59  ResponseHandler::shared_pointer const & responseHandler, osiSockAddr& address,
60  epics::pvData::int8 transportRevision, epics::pvData::int16 priority);
61 private:
62  /**
63  * Lock timeout
64  */
65  static const int LOCK_TIMEOUT = 20*1000; // 20s
66 
67  /**
68  * Context instance.
69  */
70  Context::weak_pointer _context;
71 
72  /**
73  * Receive buffer size.
74  */
75  int _receiveBufferSize;
76 
77  /**
78  * Heartbeat interval.
79  */
80  float _heartbeatInterval;
81 
82  /**
83  * Tries to connect to the given address.
84  * @param[in] address
85  * @param[in] tries
86  * @return the SOCKET
87  * @throws IOException
88  */
89  SOCKET tryConnect(osiSockAddr& address, int tries);
90 
91 };
92 
93 /**
94  * Channel Access Server TCP acceptor.
95  * @author <a href="mailto:matej.sekoranjaATcosylab.com">Matej Sekoranja</a>
96  * @version $Id: BlockingTCPAcceptor.java,v 1.1 2010/05/03 14:45:42 mrkraimer Exp $
97  */
98 class BlockingTCPAcceptor : public epicsThreadRunable {
99 public:
100  POINTER_DEFINITIONS(BlockingTCPAcceptor);
101 
102  BlockingTCPAcceptor(Context::shared_pointer const & context,
103  ResponseHandler::shared_pointer const & responseHandler,
104  const osiSockAddr& addr, int receiveBufferSize);
105 
106  virtual ~BlockingTCPAcceptor();
107 
108  /**
109  * Bind socket address.
110  * @return bind socket address, <code>null</code> if not binded.
111  */
113  return &_bindAddress;
114  }
115 
116  /**
117  * Destroy acceptor (stop listening).
118  */
119  void destroy();
120 
121 private:
122  virtual void run();
123 
124  /**
125  * Context instance.
126  */
127  Context::shared_pointer _context;
128 
129  /**
130  * Response handler.
131  */
132  ResponseHandler::shared_pointer _responseHandler;
133 
134  /**
135  * Bind server socket address.
136  */
137  osiSockAddr _bindAddress;
138 
139  /**
140  * Server socket channel.
141  */
142  SOCKET _serverSocketChannel;
143 
144  /**
145  * Receive buffer size.
146  */
147  int _receiveBufferSize;
148 
149  /**
150  * Destroyed flag.
151  */
152  bool _destroyed;
153 
154  epics::pvData::Mutex _mutex;
155 
156  epicsThread _thread;
157 
158  /**
159  * Initialize connection acception.
160  * @return port where server is listening
161  */
162  int initialize();
163 
164  /**
165  * Validate connection by sending a validation message request.
166  * @return <code>true</code> on success.
167  */
168  bool validateConnection(Transport::shared_pointer const & transport, const char* address);
169 };
170 
171 }
172 }
173 
174 #endif /* BLOCKINGTCP_H_ */
const osiSockAddr * getBindAddress()
Bind socket address.
Definition: blockingTCP.h:112
void destroy()
Destroy acceptor (stop listening).
virtual void authNZMessage(epics::pvData::PVStructure::shared_pointer const &data)=0
Pass data to the active security plug-in session.