19 #ifndef INCLUDE_RCF_CONNECTIONORIENTEDCLIENTTRANSPORT_HPP
20 #define INCLUDE_RCF_CONNECTIONORIENTEDCLIENTTRANSPORT_HPP
22 #include <boost/enable_shared_from_this.hpp>
24 #include <RCF/AmiThreadPool.hpp>
25 #include <RCF/AsioDeadlineTimer.hpp>
26 #include <RCF/Filter.hpp>
27 #include <RCF/ByteOrdering.hpp>
28 #include <RCF/ClientProgress.hpp>
29 #include <RCF/ClientTransport.hpp>
30 #include <RCF/Export.hpp>
31 #include <RCF/RecursionLimiter.hpp>
35 class ConnectionOrientedClientTransport;
37 class ClientFilterProxy;
39 class TcpClientTransport;
40 typedef boost::shared_ptr<TcpClientTransport> TcpClientTransportPtr;
41 class TcpClientFilterProxy;
44 typedef boost::shared_ptr<OverlappedAmi> OverlappedAmiPtr;
46 class RCF_EXPORT ConnectionOrientedClientTransport :
47 public ClientTransport,
48 public WithProgressCallback
52 ConnectionOrientedClientTransport(
const ConnectionOrientedClientTransport &rhs);
53 ConnectionOrientedClientTransport();
54 ~ConnectionOrientedClientTransport();
57 void setMaxSendSize(std::size_t maxSendSize);
58 std::size_t getMaxSendSize();
62 void read(
const ByteBuffer &byteBuffer_, std::size_t bytesRequested);
63 void write(
const std::vector<ByteBuffer> &byteBuffers);
64 std::size_t timedSend(
const std::vector<ByteBuffer> &data);
65 std::size_t timedReceive(ByteBuffer &byteBuffer, std::size_t bytesRequested);
67 void setTransportFilters(
const std::vector<FilterPtr> &filters);
68 void getTransportFilters(std::vector<FilterPtr> &filters);
69 void connectTransportFilters();
71 void connect(ClientTransportCallback &clientStub,
unsigned int timeoutMs);
72 void disconnect(
unsigned int timeoutMs);
73 int timedSend(
const char *buffer, std::size_t bufferLen);
74 int timedReceive(
char *buffer, std::size_t bufferLen);
78 void onReadCompleted(
const ByteBuffer &byteBuffer);
79 void onWriteCompleted(std::size_t bytes);
81 void setWireFilters(
const std::vector<FilterPtr> & wireFilters);
85 std::size_t mMaxSendSize;
86 std::size_t mBytesTransferred;
87 std::size_t mBytesSent;
88 std::size_t mBytesRead;
89 std::size_t mBytesTotal;
91 unsigned int mEndTimeMs;
93 std::vector<FilterPtr> mTransportFilters;
94 std::vector<FilterPtr> mWireFilters;
95 std::vector<ByteBuffer> mByteBuffers;
96 std::vector<ByteBuffer> mSlicedByteBuffers;
97 ReallocBufferPtr mReadBufferPtr;
98 ReallocBufferPtr mReadBuffer2Ptr;
100 friend class ClientFilterProxy;
101 friend class ClientTcpFrame;
102 friend class ClientHttpFrame;
106 virtual std::size_t implRead(
107 const ByteBuffer &byteBuffer_,
108 std::size_t bytesRequested) = 0;
110 virtual std::size_t implReadAsync(
111 const ByteBuffer &byteBuffer_,
112 std::size_t bytesRequested) = 0;
114 virtual std::size_t implWrite(
115 const std::vector<ByteBuffer> &byteBuffers) = 0;
117 virtual std::size_t implWriteAsync(
118 const std::vector<ByteBuffer> &byteBuffers) = 0;
120 virtual void implConnect(
121 ClientTransportCallback &clientStub,
122 unsigned int timeoutMs) = 0;
124 virtual void implConnectAsync(
125 ClientTransportCallback &clientStub,
126 unsigned int timeoutMs) = 0;
128 virtual void implClose() = 0;
140 std::size_t mReadBufferPos;
141 std::size_t mWriteBufferPos;
143 ClientTransportCallback * mpClientStub;
145 ByteBuffer * mpClientStubReadBuffer;
146 ByteBuffer mReadBuffer;
147 std::size_t mBytesToRead;
148 std::size_t mBytesRequested;
149 ByteBuffer mByteBuffer;
152 OverlappedAmiPtr mOverlappedPtr;
155 MutexPtr mSocketOpsMutexPtr;
159 typedef boost::shared_ptr<Lock> LockPtr;
161 AsioDeadlineTimerPtr mAsioTimerPtr;
163 friend class TcpClientFilterProxy;
170 boost::uint32_t timeoutMs,
171 ClientTransportCallback *pClientStub);
173 void onTimerExpired();
176 RecursionState<std::size_t, int> mRecursionState;
181 void onTransitionCompleted(std::size_t bytesTransferred);
183 void onCompletion(
int bytesTransferred);
184 void onTimedRecvCompleted(
int ret,
int err);
185 void onTimedSendCompleted(
int ret,
int err);
186 void onConnectCompleted(
int err);
189 void onTransitionCompleted_(std::size_t bytesTransferred);
190 void issueRead(
const ByteBuffer &buffer, std::size_t bytesToRead);
191 void issueWrite(
const std::vector<ByteBuffer> &byteBuffers);
194 ClientTransportCallback &clientStub,
195 const std::vector<ByteBuffer> &data,
196 unsigned int timeoutMs);
199 ClientTransportCallback &clientStub,
200 ByteBuffer &byteBuffer,
201 unsigned int timeoutMs);
203 void setSocketOpsMutex(MutexPtr mutexPtr);
205 friend class OverlappedAmi;
211 #endif // ! INCLUDE_RCF_CONNECTIONORIENTEDCLIENTTRANSPORT_HPP