28 const GNet::Location & location ,
unsigned int connect_timeout ,
unsigned int response_timeout ) :
29 GNet::
Client(location,connect_timeout,response_timeout,0U,config()) ,
35 G_DEBUG(
"GSmtp::RequestClient::ctor: " << location.
displayString() <<
": "
36 << connect_timeout <<
" " << response_timeout ) ;
50 G_DEBUG(
"GSmtp::RequestClient::onConnect" ) ;
52 send( requestLine(m_request) ) ;
57 G_DEBUG(
"GSmtp::RequestClient::request: \"" << request_payload <<
"\"" ) ;
58 if( busy() )
throw ProtocolError() ;
59 m_request = request_payload ;
60 m_timer.startTimer( 0U ) ;
68 void GSmtp::RequestClient::onTimeout()
71 send( requestLine(m_request) ) ;
76 return !m_request.empty() ;
91 G_WARNING(
"GSmtp::RequestClient::onDeleteImp: error: " << reason ) ;
96 eventSignal().emit( m_key , reason.empty() ? std::string(
"error") : reason ) ;
107 std::string line( line_data , line_size ) ;
108 G_DEBUG(
"GSmtp::RequestClient::onReceive: [" <<
G::Str::printable(line) <<
"]" ) ;
112 eventSignal().emit( m_key , result(line) ) ;
121 std::string GSmtp::RequestClient::requestLine(
const std::string & request_payload )
const
123 return request_payload + m_eol ;
126 std::string GSmtp::RequestClient::result( std::string line )
const
129 return !m_ok.empty() && line.find(m_ok) == 0U ? std::string() : line ;
static LineBufferConfig newline()
Convenience factory function.
static std::string printable(const std::string &in, char escape= '\\')
Returns a printable represention of the given input string.
virtual void onDeleteImp(const std::string &reason) override
Override from GNet::HeapClient.
virtual void onConnect() override
Override from GNet::SimpleClient.
std::string displayString() const
Returns a string representation for logging and debug.
virtual ~RequestClient()
Destructor.
virtual void onDeleteImp(const std::string &) override
Override from GNet::Client.
virtual bool onReceive(const char *, size_t, size_t) override
Override from GNet::Client.
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.
static void trimRight(std::string &s, const std::string &ws, size_type limit=0U)
Trims the rhs of s, taking off up to 'limit' of the 'ws' characters.
A configuration structure for GNet::LineBuffer.
virtual void onSecure(const std::string &) override
Override from GNet::SocketProtocolSink.
A class which acts as an SMTP client, extracting messages from a message store and forwarding them to...
virtual void onSendComplete() override
Override from GNet::BufferedClient.
void request(const std::string &)
Issues a request.
bool busy() const
Returns true after request() and before the subsequent event signal.
virtual void onDelete(const std::string &) override
Override from GNet::HeapClient.
RequestClient(const std::string &key, const std::string &ok, const GNet::Location &host_and_service, unsigned int connect_timeout, unsigned int response_timeout)
Constructor.
A network client class that interacts with a remote server using a stateless line-based request/respo...