26 const GNet::Location & location ,
unsigned int connect_timeout ,
unsigned int response_timeout ) :
27 GNet::
Client(es,location,netConfig(connect_timeout,response_timeout)) ,
33 G_DEBUG(
"GSmtp::RequestClient::ctor: " << location.
displayString() <<
": "
34 << connect_timeout <<
" " << response_timeout ) ;
37GNet::Client::Config GSmtp::RequestClient::netConfig(
unsigned int connection_timeout ,
unsigned int response_timeout )
40 net_config.connection_timeout = connection_timeout ;
41 net_config.response_timeout = response_timeout ;
45void GSmtp::RequestClient::onConnect()
47 G_DEBUG(
"GSmtp::RequestClient::onConnect" ) ;
49 send( requestLine(m_request) ) ;
54 G_DEBUG(
"GSmtp::RequestClient::request: \"" << request_payload <<
"\"" ) ;
56 throw ProtocolError() ;
58 m_request = request_payload ;
59 m_timer.startTimer( 0U ) ;
67void GSmtp::RequestClient::onTimeout()
70 send( requestLine(m_request) ) ;
75 return !m_request.empty() ;
78void GSmtp::RequestClient::onDelete(
const std::string & reason )
81 G_WARNING(
"GSmtp::RequestClient::onDelete: error: " << reason ) ;
84void GSmtp::RequestClient::onSecure(
const std::string & ,
const std::string & ,
const std::string & )
88bool GSmtp::RequestClient::onReceive(
const char * line_data , std::size_t line_size , std::size_t ,
91 std::string line( line_data , line_size ) ;
92 G_DEBUG(
"GSmtp::RequestClient::onReceive: [" <<
G::Str::printable(line) <<
"]" ) ;
96 eventSignal().emit( std::string(m_key) , result(line) , std::string() ) ;
105void GSmtp::RequestClient::onSendComplete()
109std::string GSmtp::RequestClient::requestLine(
const std::string & request_payload )
const
111 return request_payload + m_eol ;
114std::string GSmtp::RequestClient::result( std::string line )
const
117 return !m_ok.empty() && line.find(m_ok) == 0U ? std::string() : line ;
A tuple containing an ExceptionHandler interface pointer and a bound 'exception source' pointer.
static LineBufferConfig newline()
Convenience factory function.
A class that represents the remote target for out-going client connections.
std::string displayString() const
Returns a string representation for logging and debug.
A class which acts as an SMTP client, extracting messages from a message store and forwarding them to...
A network client class that interacts with a remote server using a stateless line-based request/respo...
bool busy() const
Returns true after request() and before the subsequent event signal.
RequestClient(GNet::ExceptionSink, const std::string &key, const std::string &ok, const GNet::Location &host_and_service, unsigned int connect_timeout, unsigned int response_timeout)
Constructor.
void request(const std::string &)
Issues a request.
static std::string & trimRight(std::string &s, string_view ws, std::size_t limit=0U)
Trims the rhs of s, taking off up to 'limit' of the 'ws' characters.
static std::string printable(const std::string &in, char escape='\\')
Returns a printable representation of the given input string, using chacter code ranges 0x20 to 0x7e ...
A structure containing GNet::Client configuration parameters.