Remote Call Framework 3.2
ConnectedClientTransport.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2020, Delta V Software. All rights reserved.
6 // http://www.deltavsoft.com
7 //
8 // RCF is distributed under dual licenses - closed source or GPL.
9 // Consult your particular license for conditions of use.
10 //
11 // If you have not purchased a commercial license, you are using RCF
12 // under GPL terms.
13 //
14 // Version: 3.2
15 // Contact: support <at> deltavsoft.com
16 //
17 //******************************************************************************
18 
19 #ifndef INCLUDE_RCF_CONNECTIONORIENTEDCLIENTTRANSPORT_HPP
20 #define INCLUDE_RCF_CONNECTIONORIENTEDCLIENTTRANSPORT_HPP
21 
22 #include <RCF/AsioBuffers.hpp>
23 #include <RCF/ByteBuffer.hpp>
24 #include <RCF/ClientTransport.hpp>
25 #include <RCF/Export.hpp>
26 #include <RCF/ReallocBuffer.hpp>
27 #include <RCF/RecursionLimiter.hpp>
28 #include <RCF/ThreadLibrary.hpp>
29 
30 namespace RCF {
31 
32  class ConnectedClientTransport;
33 
34  class ClientFilterProxy;
35 
36  class TcpClientTransport;
37  typedef std::shared_ptr<TcpClientTransport> TcpClientTransportPtr;
38  class TcpClientFilterProxy;
39 
40  class OverlappedAmi;
41  typedef std::shared_ptr<OverlappedAmi> OverlappedAmiPtr;
42 
43  class RCF_EXPORT ConnectedClientTransport : public ClientTransport
44  {
45  public:
46 
47  ConnectedClientTransport(const ConnectedClientTransport &rhs);
48  ConnectedClientTransport();
49  ~ConnectedClientTransport();
50 
51  void close();
52  void setMaxSendSize(std::size_t maxSendSize);
53  std::size_t getMaxSendSize();
54 
55  private:
56 
57  void read(const ByteBuffer &byteBuffer_, std::size_t bytesRequested);
58  void write(const std::vector<ByteBuffer> &byteBuffers);
59 
60  void setTransportFilters(const std::vector<FilterPtr> &filters);
61  void getTransportFilters(std::vector<FilterPtr> &filters);
62 
63  void getWireFilters(std::vector<FilterPtr> & filters);
64 
65  void connect(ClientTransportCallback &clientStub, unsigned int timeoutMs);
66  void disconnect(unsigned int timeoutMs);
67 
68  protected:
69 
70  void onReadCompleted(const ByteBuffer &byteBuffer);
71  void onWriteCompleted(std::size_t bytes);
72 
73  void getProgressInfo(RemoteCallProgressInfo & info);
74 
75  friend class HttpServerTransport;
76  friend class AsioServerTransport;
77  friend class PublishingService;
78  void setWireFilters(const std::vector<FilterPtr> & wireFilters);
79 
80  bool mOwn;
81  bool mClosed;
82  std::size_t mMaxSendSize;
83  int mError;
84  bool mNoTimeout;
85  unsigned int mEndTimeMs;
86 
87  std::vector<FilterPtr> mTransportFilters;
88  std::vector<FilterPtr> mWireFilters;
89  std::vector<ByteBuffer> mWriteBuffers;
90  std::vector<ByteBuffer> mSlicedByteBuffers;
91  ReallocBufferPtr mReadBufferPtr;
92  ReallocBufferPtr mReadBuffer2Ptr;
93 
94  friend class ClientFilterProxy;
95  friend class ClientTcpFrame;
96  friend class ClientHttpFrame;
97 
98  private:
99 
100  virtual std::size_t implRead(
101  const ByteBuffer &byteBuffer_,
102  std::size_t bytesRequested) = 0;
103 
104  virtual std::size_t implReadAsync(
105  const ByteBuffer &byteBuffer_,
106  std::size_t bytesRequested) = 0;
107 
108  virtual std::size_t implWrite(
109  const std::vector<ByteBuffer> &byteBuffers) = 0;
110 
111  virtual std::size_t implWriteAsync(
112  const std::vector<ByteBuffer> &byteBuffers) = 0;
113 
114  virtual void implConnect(
115  ClientTransportCallback &clientStub,
116  unsigned int timeoutMs) = 0;
117 
118  virtual void implConnectAsync(
119  ClientTransportCallback &clientStub,
120  unsigned int timeoutMs) = 0;
121 
122  virtual void implClose() = 0;
123 
124  public:
125 
126  enum State {
127  Connecting,
128  Reading,
129  Writing
130  };
131 
132  State mPreState;
133  State mPostState;
134  std::size_t mReadBufferPos;
135  std::size_t mWriteBufferPos;
136 
137  ClientTransportCallback * mpClientStub;
138 
139  ByteBuffer * mpClientStubReadBuffer;
140  ByteBuffer mReadBuffer;
141  std::size_t mBytesToRead;
142  std::size_t mBytesRequested;
143  ByteBuffer mReadBuffer2;
144 
145  protected:
146  friend class Subscription;
147  OverlappedAmiPtr mOverlappedPtr;
148 
149  MutexPtr mSocketOpsMutexPtr;
150 
151  AsioBuffers mAsioBuffers;
152 
153  public:
154 
155  typedef std::shared_ptr<Lock> LockPtr;
156 
157  AsioDeadlineTimerPtr mAsioTimerPtr;
158 
159  friend class TcpClientFilterProxy;
160 
161  public:
162 
163  void cancel();
164 
165  void setTimer(
166  std::uint32_t timeoutMs,
167  ClientTransportCallback *pClientStub);
168 
169  void onTimerExpired();
170 
171  private:
172  RecursionState<std::size_t, int> mRecursionState;
173 
174  void fireProgressEvent();
175 
176  // TODO: Access control.
177  public:
178 
179  void onTransitionCompleted(std::size_t bytesTransferred);
180 
181  void onCompletion(int bytesTransferred);
182  void onTimedRecvCompleted(int ret, int err);
183  void onTimedSendCompleted(int ret, int err);
184  void onConnectCompleted(int err);
185 
186  void transition();
187  void onTransitionCompleted_(std::size_t bytesTransferred);
188  void issueRead(const ByteBuffer &buffer, std::size_t bytesToRead);
189  void issueWrite(const std::vector<ByteBuffer> &byteBuffers);
190 
191  int send(
192  ClientTransportCallback &clientStub,
193  const std::vector<ByteBuffer> &data,
194  unsigned int timeoutMs);
195 
196  int receive(
197  ClientTransportCallback &clientStub,
198  ByteBuffer &byteBuffer,
199  unsigned int timeoutMs);
200 
201  void setSocketOpsMutex(MutexPtr mutexPtr);
202 
203  friend class OverlappedAmi;
204 
205  };
206 
207 } // namespace RCF
208 
209 #endif // ! INCLUDE_RCF_CONNECTIONORIENTEDCLIENTTRANSPORT_HPP
Definition: AmiIoHandler.hpp:24