Remote Call Framework 3.3
ConnectedClientTransport.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2022, Delta V Software. All rights reserved.
6 // https://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 under GPL terms.
12 //
13 // Version: 3.3
14 // Contact: support <at> deltavsoft.com
15 //
16 //******************************************************************************
17 
18 #ifndef INCLUDE_RCF_CONNECTIONORIENTEDCLIENTTRANSPORT_HPP
19 #define INCLUDE_RCF_CONNECTIONORIENTEDCLIENTTRANSPORT_HPP
20 
21 #include <RCF/AsioBuffers.hpp>
22 #include <RCF/ByteBuffer.hpp>
23 #include <RCF/ClientTransport.hpp>
24 #include <RCF/Export.hpp>
25 #include <RCF/ReallocBuffer.hpp>
26 #include <RCF/RecursionLimiter.hpp>
27 #include <RCF/ThreadLibrary.hpp>
28 
29 namespace RCF {
30 
31  class ConnectedClientTransport;
32 
33  class ClientFilterProxy;
34 
35  class TcpClientTransport;
36  typedef std::shared_ptr<TcpClientTransport> TcpClientTransportPtr;
37  class TcpClientFilterProxy;
38 
39  class OverlappedAmi;
40  typedef std::shared_ptr<OverlappedAmi> OverlappedAmiPtr;
41 
42  class RCF_EXPORT ConnectedClientTransport : public ClientTransport
43  {
44  public:
45 
46  ConnectedClientTransport(const ConnectedClientTransport &rhs);
47  ConnectedClientTransport();
48  ~ConnectedClientTransport();
49 
50  void close();
51  void setMaxSendSize(std::size_t maxSendSize);
52  std::size_t getMaxSendSize();
53 
54  private:
55 
56  void read(const ByteBuffer &byteBuffer_, std::size_t bytesRequested);
57  void write(const std::vector<ByteBuffer> &byteBuffers);
58 
59  void setTransportFilters(const std::vector<FilterPtr> &filters);
60  void getTransportFilters(std::vector<FilterPtr> &filters);
61 
62  void getWireFilters(std::vector<FilterPtr> & filters);
63 
64  void connect(ClientTransportCallback &clientStub, unsigned int timeoutMs);
65  void disconnect(unsigned int timeoutMs);
66 
67  protected:
68 
69  void onReadCompleted(const ByteBuffer &byteBuffer);
70  void onWriteCompleted(std::size_t bytes);
71 
72  void getProgressInfo(RemoteCallProgressInfo & info);
73 
74  friend class HttpServerTransport;
75  friend class AsioServerTransport;
76  friend class PublishingService;
77  void setWireFilters(const std::vector<FilterPtr> & wireFilters);
78 
79  bool mOwn;
80  bool mClosed;
81  std::size_t mMaxSendSize;
82  int mError;
83  bool mNoTimeout;
84  unsigned int mEndTimeMs;
85 
86  std::vector<FilterPtr> mTransportFilters;
87  std::vector<FilterPtr> mWireFilters;
88  std::vector<ByteBuffer> mWriteBuffers;
89  std::vector<ByteBuffer> mSlicedByteBuffers;
90  ReallocBufferPtr mReadBufferPtr;
91  ReallocBufferPtr mReadBuffer2Ptr;
92 
93  friend class ClientFilterProxy;
94  friend class ClientTcpFrame;
95  friend class ClientHttpFrame;
96 
97  private:
98 
99  virtual std::size_t implRead(
100  const ByteBuffer &byteBuffer_,
101  std::size_t bytesRequested) = 0;
102 
103  virtual std::size_t implReadAsync(
104  const ByteBuffer &byteBuffer_,
105  std::size_t bytesRequested) = 0;
106 
107  virtual std::size_t implWrite(
108  const std::vector<ByteBuffer> &byteBuffers) = 0;
109 
110  virtual std::size_t implWriteAsync(
111  const std::vector<ByteBuffer> &byteBuffers) = 0;
112 
113  virtual void implConnect(
114  ClientTransportCallback &clientStub,
115  unsigned int timeoutMs) = 0;
116 
117  virtual void implConnectAsync(
118  ClientTransportCallback &clientStub,
119  unsigned int timeoutMs) = 0;
120 
121  virtual void implClose() = 0;
122 
123  public:
124 
125  enum State {
126  Connecting,
127  Reading,
128  Writing
129  };
130 
131  State mPreState;
132  State mPostState;
133  std::size_t mReadBufferPos;
134  std::size_t mWriteBufferPos;
135  bool mSendingZeroSizeChunk = false;
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:23