You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
847 B
57 lines
847 B
#ifndef TCP_CLIENT_HPP
|
|
#define TCP_CLIENT_HPP
|
|
|
|
#include "TcpConnection.hpp"
|
|
#include "Thread.hpp"
|
|
#include "Poll.hpp"
|
|
|
|
#include <string>
|
|
|
|
|
|
class TcpClient
|
|
{
|
|
private:
|
|
|
|
class WatcherThread : public Thread
|
|
, public Poll
|
|
{
|
|
public:
|
|
WatcherThread( TcpClient &data );
|
|
|
|
// overringind Poll's accept behaviour
|
|
void acceptClient();
|
|
void handleClient( const int fd );
|
|
bool receive( const int fd );
|
|
|
|
private:
|
|
void* run();
|
|
|
|
TcpClient &m_tcpClient;
|
|
};
|
|
|
|
|
|
public:
|
|
|
|
TcpClient ( const std::string host,
|
|
const std::string port );
|
|
|
|
virtual ~TcpClient();
|
|
|
|
bool connect();
|
|
void disconnect();
|
|
|
|
bool send( const void* message, const int length );
|
|
|
|
private:
|
|
|
|
// virtual void onDisconnect() = 0;
|
|
|
|
TcpConnection m_connection;
|
|
WatcherThread m_watcher;
|
|
|
|
};
|
|
|
|
#endif // TCP_CLIENT_HPP
|
|
|
|
|