14 #include "../../Util/Common.h" 15 #include "IPAddress.h" 16 #include "../../Util/DelegateOneArgument.h" 17 #include "SocketErrors.h" 19 #include <boost/bind.hpp> 20 #include <boost/asio.hpp> 21 #include <boost/asio/deadline_timer.hpp> 22 #include <boost/array.hpp> 23 #include <boost/shared_ptr.hpp> 24 #include <boost/enable_shared_from_this.hpp> 25 #include <boost/thread/recursive_mutex.hpp> 26 #include <boost/thread/lock_guard.hpp> 29 #pragma warning(disable:4786) // STL library: disable warning 4786; this warning is generated due to a Microsoft bug 34 using boost::asio::ip::tcp;
45 typedef DelegateOneArgument<SocketErrors> TCPConnectionDelegate;
46 typedef DelegateOneArgument<boost::shared_ptr<vector<unsigned char> > > TCPDataReadDelegate;
47 typedef DelegateOneArgument<SocketErrors> TCPDataWriteDelegate;
52 class TCPClient :
public boost::enable_shared_from_this<TCPClient>
62 TCPClient (boost::asio::io_service& io_service);
67 virtual void Dispose();
75 void Connect (boost::shared_ptr<IPAddress> ipAddress,
unsigned short int ipPort,
long int timeout, boost::shared_ptr<TCPConnectionDelegate> callback);
81 void SynchConnect (boost::shared_ptr<IPAddress> ipAddress,
unsigned short int ipPort);
90 void AsynchRead (boost::shared_ptr<TCPDataReadDelegate> callback);
96 void AsynchWrite (boost::shared_ptr<vector<unsigned char> > data, boost::shared_ptr<TCPDataWriteDelegate> callback);
101 boost::shared_ptr<vector<unsigned char> > SynchRead ();
106 void SynchWrite (boost::shared_ptr<vector<unsigned char> > data);
108 bool CallbackCallInProgress();
133 void OnBoostAsioConnect(
const boost::system::error_code& code);
138 void OnBoostAsioConnectTimedout(
const boost::system::error_code& code);
144 void OnBoostAsioDataReceived(
const boost::system::error_code& error,
long int length);
152 void OnBoostAsioDataSent(boost::shared_ptr<unsigned char> bufferOutput,
size_t length,
size_t transferred,
const boost::system::error_code& error);
158 const static long int READ_BUFFER_SIZE = 4096;
160 boost::asio::io_service& boostIoService;
161 tcp::resolver boostTcpResolver;
162 tcp::socket boostTcpSocket;
163 boost::asio::deadline_timer boostTimerTaskDeadline;
164 boost::array<char, READ_BUFFER_SIZE> boostTcpInputBuffer;
166 boost::shared_ptr<TCPConnectionDelegate> callbackTCPConnection;
167 boost::shared_ptr<TCPDataReadDelegate> callbackTCPDataRead;
168 boost::shared_ptr<TCPDataWriteDelegate> callbackTCPDataWrite;
170 boost::recursive_mutex mtxDisconnection;
172 long int counterAsyncReadOperationsInProgress;
173 long int counterAsyncWriteOperationsInProgress;
175 bool isCallbackCallInProgress;
Definition: BuddyOnlineState.h:15
Definition: SmartFox.cpp:24