• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ io_service::strand类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中boost::asio::io_service::strand的典型用法代码示例。如果您正苦于以下问题:C++ strand类的具体用法?C++ strand怎么用?C++ strand使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了strand类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: nextOperation

	/// 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;
		}
	}
开发者ID:Wolframe,项目名称:Wolframe,代码行数:61,代码来源:connectionBase.hpp


示例2: justdoit

 void justdoit()
 {
     rc_->get(strand_.wrap(
         boost::bind(&tormoz_get::handle_done, shared_from_this(), _1, _2))
              );
     timer_.expires_from_now(boost::posix_time::milliseconds(100));
     timer_.async_wait(strand_.wrap(boost::bind(&tormoz_get::handle_timeout, shared_from_this(), _1)));
 }
开发者ID:alexeimoisseev,项目名称:NwSMTP,代码行数:8,代码来源:tormoz2.cpp


示例3: do_finish

    void do_finish (
        std::string name,
        boost::system::error_code const& ec,
        HandlerType handler,
        boost::asio::ip::tcp::resolver::iterator iter,
        CompletionCounter)
    {
        if (ec == boost::asio::error::operation_aborted)
            return;

        std::vector <beast::IP::Endpoint> addresses;

        // If we get an error message back, we don't return any
        // results that we may have gotten.
        if (!ec)
        {
            while (iter != boost::asio::ip::tcp::resolver::iterator())
            {
                addresses.push_back (beast::IPAddressConversion::from_asio (*iter));
                ++iter;
            }
        }

        handler (name, addresses);

        m_io_service.post (m_strand.wrap (std::bind (
            &ResolverAsioImpl::do_work, this,
                CompletionCounter (this))));
    }
开发者ID:mellery451,项目名称:rippled,代码行数:29,代码来源:ResolverAsio.cpp


示例4: do_resolve

    void do_resolve (std::vector <std::string> const& names,
        HandlerType const& handler, CompletionCounter)
    {
        check_precondition (! names.empty());

        if (m_called_stop.load () == 0)
        {
            // TODO NIKB use emplace_back once we move to C++11
            m_work.push_back(Work(names, handler));

            m_journal.debug <<
                "Queued new job with " << names.size() <<
                " tasks. " << m_work.size() << " jobs outstanding.";

            if (m_work.size() == 1)
            {
                check_precondition (m_idle);

                m_journal.trace << "Waking up";
                m_idle = false;

                m_io_service.post (m_strand.wrap (boost::bind (
                    &NameResolverImpl::do_work, this,
                    CompletionCounter(this))));
            }
        }
    }
开发者ID:12w21,项目名称:rippled,代码行数:27,代码来源:NameResolver.cpp


示例5: on_timer

        // Called when the timer expires.
        // We operate the timer continuously this simplifies the code.
        //
        void on_timer(error_code ec)
        {
            if(ec && ec != boost::asio::error::operation_aborted)
                return fail("timer", ec);

            // Verify that the timer really expired
            // since the deadline may have moved.
            //
            if(timer_.expires_at() <= clock_type::now())
            {
                // Closing the socket cancels all outstanding
                // operations. They will complete with
                // boost::asio::error::operation_aborted
                //
                ws_.next_layer().close(ec);
                return;
            }

            // Wait on the timer
            timer_.async_wait(
                strand_.wrap(std::bind(
                    &connection::on_timer,
                    shared_from_this(),
                    std::placeholders::_1)));
        }
开发者ID:vinniefalco,项目名称:Beast,代码行数:28,代码来源:websocket_server_async.cpp


示例6: start

	inline void connection::start() {
	    socket_.async_read_some(boost::asio::buffer(buffer_),
		    strand_.wrap(
			 boost::bind(&connection::handle_read, shared_from_this(),
				     boost::asio::placeholders::error,
				     boost::asio::placeholders::bytes_transferred)));
	}
开发者ID:RubenVerborgh,项目名称:SWObjects,代码行数:7,代码来源:WEBserver_asio.hpp


示例7: PostRandomTicket

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));
}
开发者ID:iamwljiang,项目名称:loginsystem,代码行数:7,代码来源:AuthenticationCenter.cpp


示例8: process_message

 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));
 }
开发者ID:mrZreat,项目名称:AsioTest,代码行数:9,代码来源:echo_server.cpp


示例9: PostErrorMessage

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
                ));
}
开发者ID:iamwljiang,项目名称:loginsystem,代码行数:9,代码来源:AuthenticationCenter.cpp


示例10: stop_async

    void stop_async () override
    {
        if (m_stop_called.exchange (true) == false)
        {
            m_io_service.dispatch (m_strand.wrap (std::bind (
                &ResolverAsioImpl::do_stop,
                    this, CompletionCounter (this))));

            JLOG(m_journal.debug()) << "Queued a stop request";
        }
    }
开发者ID:mellery451,项目名称:rippled,代码行数:11,代码来源:ResolverAsio.cpp


示例11: stop_async

    void stop_async ()
    {
        if (m_called_stop.exchange (1) == 0)
        {
            m_io_service.dispatch (m_strand.wrap (boost::bind (
                &NameResolverImpl::do_stop, 
                    this, CompletionCounter (this))));

            m_journal.debug << "Stopping";
        }
    }
开发者ID:12w21,项目名称:rippled,代码行数:11,代码来源:NameResolver.cpp


示例12: do_read

        // Read a message from the websocket stream
        void do_read()
        {
            // Put the read on the timer
            timer_.expires_from_now(std::chrono::seconds(15));

            // Read a message
            ws_.async_read(buffer_,
                strand_.wrap(std::bind(
                    &connection::on_read,
                    shared_from_this(),
                    std::placeholders::_1)));
        }
开发者ID:vinniefalco,项目名称:Beast,代码行数:13,代码来源:websocket_server_async.cpp


示例13: resolve

    void resolve (
        std::vector <std::string> const& names,
        HandlerType const& handler)
    {
        check_precondition (m_called_stop.load () == 0);
        check_precondition (!names.empty());

        // TODO NIKB use rvalue references to construct and move
        //           reducing cost.
        m_io_service.dispatch (m_strand.wrap (boost::bind (
            &NameResolverImpl::do_resolve, this,
            names, handler, CompletionCounter(this))));
    }
开发者ID:12w21,项目名称:rippled,代码行数:13,代码来源:NameResolver.cpp


示例14: handle_read

	inline void connection::handle_read(const boost::system::error_code& e,
					    std::size_t bytes_transferred) {
	    if (!e) {
		boost::tribool result;
		boost::tie(result, boost::tuples::ignore) = request_parser_.parse(
		  *request_, buffer_.data(), buffer_.data() + bytes_transferred);

		if (result) {
		    try {
			request_handler_.handle_request(*request_, reply_);
		    } catch (webserver::reply rep) {
			reply_ = rep;
		    }
		    std::cerr << reply_.content << std::endl;
		    boost::asio::async_write(socket_, reply_.to_buffers(),
		     strand_.wrap(
			  boost::bind(&connection::handle_write, shared_from_this(),
				      boost::asio::placeholders::error)));
		} else if (!result) {
		    reply_ = reply::stock_reply(reply::bad_request);
		    boost::asio::async_write(socket_, reply_.to_buffers(),
		     strand_.wrap(
			  boost::bind(&connection::handle_write, shared_from_this(),
				      boost::asio::placeholders::error)));
		} else {
		    socket_.async_read_some(boost::asio::buffer(buffer_),
			    strand_.wrap(
				 boost::bind(&connection::handle_read, shared_from_this(),
					     boost::asio::placeholders::error,
					     boost::asio::placeholders::bytes_transferred)));
		}
	    }

	    // If an error occurs then no new asynchronous operations are started. This
	    // means that all shared_ptr references to the connection object will
	    // disappear and the object will be destroyed automatically after this
	    // handler returns. The connection class's destructor closes the socket.
	}
开发者ID:RubenVerborgh,项目名称:SWObjects,代码行数:38,代码来源:WEBserver_asio.hpp


示例15: handle_read

 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);
     }
 }
开发者ID:mrZreat,项目名称:AsioTest,代码行数:14,代码来源:echo_server.cpp


示例16: resolve

    void resolve (
        std::vector <std::string> const& names,
        HandlerType const& handler) override
    {
        assert (m_stop_called == false);
        assert (m_stopped == true);
        assert (!names.empty());

        // TODO NIKB use rvalue references to construct and move
        //           reducing cost.
        m_io_service.dispatch (m_strand.wrap (std::bind (
            &ResolverAsioImpl::do_resolve, this,
                names, handler, CompletionCounter (this))));
    }
开发者ID:mellery451,项目名称:rippled,代码行数:14,代码来源:ResolverAsio.cpp


示例17: setTimeout

	/// Set / reset the timeout timer
	void setTimeout( unsigned timeout )
	{
		if ( timeout == 0 )	{
			LOG_TRACE << "Timeout for connection to " << identifier() << " reset";
			m_timer.cancel();
		}
		else	{
			m_timer.cancel();
			m_timer.expires_from_now( boost::posix_time::seconds( timeout ));
			m_timer.async_wait( m_strand.wrap( boost::bind( &ConnectionBase::handleTimeout,
									this->shared_from_this(),
									boost::asio::placeholders::error )));
			LOG_TRACE << "Timeout for connection to " << identifier() << " set to " << timeout << "s";
		}
	}
开发者ID:Wolframe,项目名称:Wolframe,代码行数:16,代码来源:connectionBase.hpp


示例18: handle_timeout

    void handle_timeout(const boost::system::error_code& ec)
    {
        if (--count_ > 0)
        {
            rc_->stop();
            rc_.reset( new rc_check(timer_.io_service(), std::string(p_.pp.login).append("@").append(p_.pp.domain),
                            p_.pp.ukey, p_.l, 1) );

            timer_.expires_from_now(boost::posix_time::milliseconds(rand_r(&seed_) % 500));
            timer_.async_wait(strand_.wrap(boost::bind(&tormoz_get::handle_timeout, shared_from_this(), _1)));
        }
        else if (rc_)
        {
            rc_->stop();
            rc_.reset();
        }
    }
开发者ID:alexeimoisseev,项目名称:NwSMTP,代码行数:17,代码来源:tormoz2.cpp


示例19: WSClientImpl

 WSClientImpl(Config const& cfg, bool v2)
     : work_(ios_)
     , strand_(ios_)
     , thread_([&] {
     ios_.run();
 })
 , stream_(ios_)
 , ws_(stream_)
 {
     auto const ep = getEndpoint(cfg, v2);
     stream_.connect(ep);
     ws_.handshake(ep.address().to_string() +
                   ":" + std::to_string(ep.port()), "/");
     ws_.async_read(op_, rb_,
                    strand_.wrap(std::bind(&WSClientImpl::on_read_msg,
                                           this, beast::asio::placeholders::error)));
 }
开发者ID:yunsite,项目名称:rippled,代码行数:17,代码来源:WSClient.cpp


示例20: onTimer

    void
    onTimer (boost::system::error_code ec)
    {
        if (ec)
        {
            if (ec != boost::asio::error::operation_aborted)
                journal_.error <<
                    "onTimer: " << ec.message();
            return;
        }

        logic_.onTimer();

        timer_.expires_from_now(std::chrono::seconds(1), ec);
        timer_.async_wait(strand_.wrap(exec_.wrap(
            std::bind(&ManagerImp::onTimer, this,
                beast::asio::placeholders::error))));
    }
开发者ID:E-LLP,项目名称:rippled,代码行数:18,代码来源:ValidatorManager.cpp



注:本文中的boost::asio::io_service::strand类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ ip::address类代码示例发布时间:2022-05-31
下一篇:
C++ asio::streambuf类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap