27 const GNet::Location & location ,
unsigned int connection_timeout ,
unsigned int response_timeout ,
28 unsigned int idle_timeout ) :
31 .set_line_buffer_config(
GNet::LineBuffer::
Config::newline())
32 .set_connection_timeout(connection_timeout)
33 .set_response_timeout(response_timeout)
34 .set_idle_timeout(idle_timeout)) ,
40 G_DEBUG(
"GSmtp::RequestClient::ctor: " << location.
displayString() <<
": "
41 << connection_timeout <<
" " << response_timeout ) ;
44void GSmtp::RequestClient::onConnect()
46 G_DEBUG(
"GSmtp::RequestClient::onConnect" ) ;
48 send( requestLine(m_request) ) ;
53 G_DEBUG(
"GSmtp::RequestClient::request: \"" << request_payload <<
"\"" ) ;
55 throw ProtocolError() ;
57 m_request = request_payload ;
58 m_timer.startTimer( 0U ) ;
66void GSmtp::RequestClient::onTimeout()
69 send( requestLine(m_request) ) ;
74 return !m_request.empty() ;
77void GSmtp::RequestClient::onDelete(
const std::string & reason )
80 G_WARNING(
"GSmtp::RequestClient::onDelete: error: " << reason ) ;
83void GSmtp::RequestClient::onSecure(
const std::string & ,
const std::string & ,
const std::string & )
87bool GSmtp::RequestClient::onReceive(
const char * line_data , std::size_t line_size , std::size_t ,
90 std::string line( line_data , line_size ) ;
91 G_DEBUG(
"GSmtp::RequestClient::onReceive: [" <<
G::Str::printable(line) <<
"]" ) ;
95 eventSignal().emit( std::string(m_key) , result(line) , std::string() ) ;
104void GSmtp::RequestClient::onSendComplete()
108std::string GSmtp::RequestClient::requestLine(
const std::string & request_payload )
const
110 return request_payload + m_eol ;
113std::string GSmtp::RequestClient::result( std::string line )
const
116 return !m_ok.empty() && line.find(m_ok) == 0U ? std::string() : line ;
A lightweight object containing an ExceptionHandler pointer, optional ExceptionSource pointer and opt...
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...
bool busy() const
Returns true after request() and before the subsequent event signal.
RequestClient(GNet::EventState, 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.
void request(const std::string &)
Issues a request.
static std::string & trimRight(std::string &s, std::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.