26 const GNet::Location & location ,
unsigned int connection_timeout ,
unsigned int response_timeout ,
27 unsigned int idle_timeout ) :
30 .set_line_buffer_config(
GNet::LineBuffer::
Config::newline())
31 .set_connection_timeout(connection_timeout)
32 .set_response_timeout(response_timeout)
33 .set_idle_timeout(idle_timeout)) ,
39 G_DEBUG(
"GSmtp::RequestClient::ctor: " << location.
displayString() <<
": "
40 << connection_timeout <<
" " << response_timeout ) ;
43void GSmtp::RequestClient::onConnect()
45 G_DEBUG(
"GSmtp::RequestClient::onConnect" ) ;
47 send( requestLine(m_request) ) ;
52 G_DEBUG(
"GSmtp::RequestClient::request: \"" << request_payload <<
"\"" ) ;
54 throw ProtocolError() ;
56 m_request = request_payload ;
57 m_timer.startTimer( 0U ) ;
65void GSmtp::RequestClient::onTimeout()
68 send( requestLine(m_request) ) ;
73 return !m_request.empty() ;
76void GSmtp::RequestClient::onDelete(
const std::string & reason )
79 G_WARNING(
"GSmtp::RequestClient::onDelete: error: " << reason ) ;
82void GSmtp::RequestClient::onSecure(
const std::string & ,
const std::string & ,
const std::string & )
86bool GSmtp::RequestClient::onReceive(
const char * line_data , std::size_t line_size , std::size_t ,
89 std::string line( line_data , line_size ) ;
90 G_DEBUG(
"GSmtp::RequestClient::onReceive: [" <<
G::Str::printable(line) <<
"]" ) ;
94 eventSignal().emit( std::string(m_key) , result(line) , std::string() ) ;
103void GSmtp::RequestClient::onSendComplete()
107std::string GSmtp::RequestClient::requestLine(
const std::string & request_payload )
const
109 return request_payload + m_eol ;
112std::string GSmtp::RequestClient::result( std::string line )
const
115 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.
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, sending messages to a remote SMTP server.
A network client class that interacts with a remote server using a stateless line-based request/respo...
RequestClient(GNet::ExceptionSink, const std::string &key, const std::string &ok, const GNet::Location &host_and_service, unsigned int connection_timeout, unsigned int response_timeout, unsigned int idle_timeout)
Constructor.
bool busy() const
Returns true after request() and before the subsequent event signal.
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.