21 #ifndef G_SIMPLE_CLIENT_H
22 #define G_SIMPLE_CLIENT_H
63 enum ConnectStatus { Success , Failure , ImmediateSuccess } ;
64 enum State { Idle , Resolving , Connecting , Connected , Socksing , Testing } ;
65 G_EXCEPTION( DnsError ,
"dns error" ) ;
66 G_EXCEPTION( ConnectError ,
"connect failure" ) ;
67 G_EXCEPTION( SocksError ,
"socks error" ) ;
68 G_EXCEPTION( NotConnected ,
"socket not connected" ) ;
69 typedef std::string::size_type size_type ;
72 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 ;
123 bool send(
const std::string & data , std::string::size_type offset = 0 ) ;
153 static bool connectError(
const std::string & reason ) ;
157 std::string
logId()
const ;
166 void startConnecting() ;
167 void bindLocalAddress(
const Address & ) ;
168 void setState( State ) ;
169 void sendSocksRequest() ;
170 bool readSocksResponse() ;
171 void logFlowControlAsserted()
const ;
172 void logFlowControlReleased()
const ;
173 virtual void onResolved( std::string ,
Location )
override ;
174 void onConnectTimer() ;
178 unique_ptr<StreamSocket> m_socket ;
179 unique_ptr<SocketProtocol> m_sp ;
182 bool m_bind_local_address ;
186 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)
Returns true if all sent, or false if flow control was asserted.
void sslConnect()
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.
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.
SimpleClient(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.
A base class for classes that handle asynchronous events from the event loop.
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 interface which provides address information for a network connection.
virtual ~SimpleClient()
Destructor.
virtual std::pair< bool, Address > peerAddress() const override
Override from Connection.
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...
A timer class template in which the timeout is delivered to the specified method. ...
to deliver data from a socket.
StreamSocket & socket()
Returns a reference to the socket. Throws if not connected.