/// Connection base state machine void nextOperation() { NetworkOperation netOp = m_connHandler->nextOperation(); switch ( netOp.operation() ) { case NetworkOperation::READ: { LOG_TRACE << "Next operation: READ " << netOp.size() << " bytes from " << identifier(); if ( netOp.buffer() == NULL ) { LOG_FATAL << "Attempt to READ from " << identifier() << " to a NULL data block"; abort(); // here should be a system exception } if ( netOp.size() == 0 ) { LOG_FATAL << "Attempt to READ 0 bytes data block from " << identifier(); abort(); // here should be a system exception } if ( netOp.timeout() > 0 ) setTimeout( netOp.timeout()); m_readBuffer = netOp.buffer(); socket().async_read_some( boost::asio::buffer( m_readBuffer, netOp.size() ), m_strand.wrap( boost::bind( &ConnectionBase::handleRead, this->shared_from_this(), boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred ))); break; } case NetworkOperation::WRITE: { LOG_TRACE << "Next operation: WRITE " << netOp.size() << " bytes to " << identifier(); if ( netOp.data() == NULL ) { LOG_FATAL << "Attempt to WRITE a NULL data block to " << identifier(); abort(); // here should be a system exception } if ( netOp.size() == 0 ) { LOG_FATAL << "Attempt to WRITE a 0 bytes data block to " << identifier(); abort(); // here should be a system exception } if ( netOp.timeout() > 0 ) setTimeout( netOp.timeout()); boost::asio::async_write( socket(), boost::asio::buffer( netOp.data(), netOp.size() ), m_strand.wrap( boost::bind( &ConnectionBase::handleWrite, this->shared_from_this(), boost::asio::placeholders::error ))); break; } case NetworkOperation::CLOSE: { LOG_TRACE << "Next operation: CLOSE connection to " << identifier(); // Initiate graceful connection closure. setTimeout( 0 ); unregister(); m_strand.post( boost::bind( &ConnectionBase::handleShutdown, this->shared_from_this() )); break; } case NetworkOperation::NOOP: LOG_TRACE << "Next operation: NOOP on connection to " << identifier(); break; } }
void CAuthenticationCenter::PostRandomTicket(boost::shared_ptr<CTcpConnection> conn, boost::asio::io_service::strand& strand, const std::string& secret_key,std::vector<std::string> command_vec) { strand.post(boost::bind(&CAuthenticationCenter::ProcessTicketMessage,this, conn,secret_key,command_vec)); }
void process_message(message_ptr msg) { //std::cout << ">"; unsigned int msgid; msg->get_object<unsigned int>(msgid); logfile.log(boost::lexical_cast<std::string>(msgid)); //do_stuff(); //TODO: find a way to do_stuff() concurrently reply_strand_.post(boost::bind(&session::send_reply, shared_from_this(), msg)); }
void CAuthenticationCenter::PostErrorMessage(boost::shared_ptr<CTcpConnection> conn, boost::asio::io_service::strand& strand, const std::string& errmsg) { strand.post(boost::bind( &CAuthenticationCenter::ReplyErrorMessage, this,conn,errmsg )); }
void handle_read(message_ptr msg, const boost::system::error_code & error, size_t bytes_transferred) { if (!error) { request_strand_.post(boost::bind(&session::process_message, shared_from_this(), msg)); poll_message(); } else { error_handler_(error); } }
void CAuthenticationCenter::PostRandomTGT(boost::shared_ptr<CTcpConnection> conn, boost::asio::io_service::strand& strand, UserInfo &unode) { strand.post(boost::bind(&CAuthenticationCenter::ProcessTGTMessage,this,conn,unode)); }