21 #ifndef G_NET_SIMPLE_CLIENT__H
22 #define G_NET_SIMPLE_CLIENT__H
64 enum ConnectStatus { Success , Failure , ImmediateSuccess } ;
65 enum State { Idle , Resolving , Connecting , Connected , Socksing , Testing } ;
66 G_EXCEPTION( DnsError ,
"dns error" ) ;
67 G_EXCEPTION( ConnectError ,
"connect failure" ) ;
68 G_EXCEPTION( NotConnected ,
"socket not connected" ) ;
69 typedef std::string::size_type size_type ;
72 const Location & remote_info ,
bool bind_local_address =
false ,
75 unsigned int secure_connection_timeout = 0U ) ;
86 virtual std::pair<bool,Address>
localAddress()
const override ;
91 virtual std::pair<bool,Address>
peerAddress()
const override ;
127 virtual void otherEvent( EventHandler::Reason )
override ;
130 bool send(
const std::string & data , std::string::size_type offset = 0 ) ;
164 static bool connectError(
const std::string & reason ) ;
168 std::string
logId()
const ;
177 void startConnecting() ;
178 void bindLocalAddress(
const Address & ) ;
179 void setState( State ) ;
180 void logFlowControlAsserted()
const ;
181 void logFlowControlReleased()
const ;
182 virtual void onResolved( std::string ,
Location )
override ;
183 void onConnectTimer() ;
188 unique_ptr<StreamSocket> m_socket ;
189 unique_ptr<SocketProtocol> m_sp ;
190 unique_ptr<Socks> m_socks ;
193 bool m_bind_local_address ;
197 unsigned int m_secure_connection_timeout ;
virtual void onConnect()=0
Called once connected.
virtual void writeEvent() override
Override from GNet::EventHandler.
virtual void readEvent() override
Override from GNet::EventHandler.
A class for making an outgoing connection to a remote server, with support for socket-level protocols...
bool send(const std::string &data, std::string::size_type offset=0)
Sends data to the peer.
void secureConnect()
Starts TLS/SSL client-side negotiation.
A class for synchronous or asynchronous network name to address resolution.
The GNet::Address class encapsulates a TCP/UDP transport address.
virtual std::string peerCertificate() const override
Returns the peer's TLS certificate.
bool connected() const
Returns true if connected to the peer.
virtual void onConnectImp()
An alternative to onConnect() for private implementation classes.
An interface used for GNet::Resolver callbacks.
An abstract interface for handling exceptions thrown out of event-loop callbacks (socket events...
virtual void onSendComplete()=0
Called when all residual data from send() has been sent.
A class that holds a host/service name pair and the preferred address family (if any), and also the results of a name-to-address lookup, ie.
void connect()
Initates a connection to the remote server.
A derivation of GNet::Socket for a stream socket.
static Address defaultAddress()
Returns a default address, being the IPv4 wildcard address with a zero port number.
Location remoteLocation() const
Returns a Location structure containing the result of host() and service() name lookup if available...
virtual std::pair< bool, Address > localAddress() const override
Override from Connection.
A base class for classes that handle asynchronous events from the event loop.
virtual std::string connectionState() const override
Returns the connection state display string.
std::string logId() const
Returns a identification string for logging purposes.
static bool synchronousDnsDefault()
Returns true if DNS queries should normally be synchronous on this platform.
virtual void onSendImp()
Called from within send().
An abstract interface which provides address information for a network connection.
virtual ~SimpleClient()
Destructor.
virtual std::pair< bool, Address > peerAddress() const override
Override from Connection.
virtual void otherEvent(EventHandler::Reason) override
Override from GNet::EventHandler.
static bool connectError(const std::string &reason)
Returns true if the reason string implies the SimpleClient::connect() failed.
void updateLocation(const Location &)
Updates the constructor's Location object with the given one as long as both objects have the same ho...
SimpleClient(ExceptionHandler &, const Location &remote_info, bool bind_local_address=false, const Address &local_address=Address::defaultAddress(), bool sync_dns=synchronousDnsDefault(), unsigned int secure_connection_timeout=0U)
Constructor. Call connect() to start connecting.
A timer class template in which the timeout is delivered to the specified method. ...
An interface used by GNet::SocketProtocol to deliver data from a socket.
StreamSocket & socket()
Returns a reference to the socket. Throws if not connected.