21 #ifndef G_SIMPLE_CLIENT_H
22 #define G_SIMPLE_CLIENT_H
42 class ClientResolver ;
89 G_EXCEPTION( NotConnected ,
"socket not connected" ) ;
94 bool privileged =
false ,
96 unsigned int secure_connection_timeout = 0U ) ;
126 virtual std::pair<bool,Address>
peerAddress()
const ;
189 static bool canRetry(
const std::string & reason ) ;
194 std::string
logId()
const ;
201 void resolveCon(
bool ,
const Address & , std::string ) ;
207 static unsigned int getRandomPort() ;
208 bool startConnecting() ;
211 void setState(
State ) ;
212 void immediateConnection() ;
213 void sendSocksRequest() ;
214 bool readSocksResponse() ;
215 void logFlowControlAsserted()
const ;
216 void logFlowControlReleased()
const ;
219 std::auto_ptr<ClientResolver> m_resolver ;
220 std::auto_ptr<StreamSocket> m_s ;
221 std::auto_ptr<SocketProtocol> m_sp ;
227 unsigned int m_secure_connection_timeout ;
virtual void onConnect()=0
Called once connected.
std::string::size_type size_type
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 resolver class which calls SimpleClient::resolveCon() when done.
virtual std::pair< bool, Address > peerAddress() const
Override from Connection.
virtual std::string peerCertificate() const
Returns the peer's TLS certificate.
A class for asynchronous TCP name-to-address resolution.
The Address class encapsulates an IP transport address.
A class that holds a host/service name pair and optionally the results of a name-to-address lookup...
std::string::size_type size_type
A std::size_t type.
virtual void writeEvent()
Final override from GNet::EventHandler.
bool connected() const
Returns true if connected to the peer.
virtual void onConnectImp()
An alternative to onConnect() for private implementation classes.
ClientResolver(SimpleClient &)
Constructor.
SimpleClient(const ResolverInfo &remote_info, const Address &local_address=Address(0U), bool privileged=false, bool sync_dns=synchronousDnsDefault(), unsigned int secure_connection_timeout=0U)
Constructor.
void updateResolverInfo(const ResolverInfo &)
Updates the constructor's ResolverInfo object with the given one as long as both objects have the sam...
static bool canRetry(const std::string &reason)
Parses the given failure reason and returns true if the client can reasonably retry at some later tim...
virtual void onSendComplete()=0
Called when all residual data from send() has been sent.
void connect()
Initates a connection to the remote server.
A derivation of Socket for a stream socket.
A base class for classes that handle asynchronous socket events.
std::string logId() const
Returns a identification string for logging purposes.
void resolveCon(bool success, const Address &address, std::string reason)
From Resolver.
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.
#define G_EXCEPTION(class_name, description)
define as a function rather than a type if optimising for size
virtual ~SimpleClient()
Destructor.
ResolverInfo resolverInfo() const
Returns a ResolverInfo structure containing the result of host() and service() name lookup if availab...
virtual std::pair< bool, Address > localAddress() const
Override from Connection.
virtual void readEvent()
Final override from GNet::EventHandler.
An interface used by GNet::SocketProtocol to deliver data from a socket.
StreamSocket & socket()
Returns a reference to the socket. Throws if not connected.