当前位置: 首页>>代码示例>>C++>>正文


C++ io_service::post方法代码示例

本文整理汇总了C++中io_service::post方法的典型用法代码示例。如果您正苦于以下问题:C++ io_service::post方法的具体用法?C++ io_service::post怎么用?C++ io_service::post使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io_service的用法示例。


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

示例1: main

int main() {
	io_service::strand strand1(service), strand2(service);
	for (auto i = 0; i < 5; ++i)
		service.post(strand1.wrap(std::bind(func, i)));
	for (auto i = 5; i < 10; ++i)
		service.post(strand2.wrap(std::bind(func, i)));

	std::vector<std::thread> threads;
	for (auto i = 0; i < 3; ++i)
		threads.push_back(std::thread(worker_thread));

	std::this_thread::sleep_for(std::chrono::milliseconds(500));
	for (auto& th : threads) th.join();
}
开发者ID:wfxr,项目名称:CppLab,代码行数:14,代码来源:main.cpp

示例2: do_login

///登录,发送登陆请求给服务器
void talk_to_svr::do_login(const std::string &username, const std::string &password)
{
    _username = username;
    _password = password;
    std::string writeMsg("login " + username + " " + password + "\n");
    service.post(MEM_FN1(do_write, writeMsg));
}
开发者ID:coderdeng,项目名称:net_code,代码行数:8,代码来源:asyncClient.cpp

示例3: queue_request

	void tracker_manager::queue_request(
		io_service& ios
		, connection_queue& cc
		, tracker_request req
		, std::string const& auth
		, boost::weak_ptr<request_callback> c)
	{
		mutex_t::scoped_lock l(m_mutex);
		TORRENT_ASSERT(req.num_want >= 0);
		TORRENT_ASSERT(!m_abort || req.event == tracker_request::stopped);
		if (m_abort && req.event != tracker_request::stopped) return;
		if (req.event == tracker_request::stopped)
			req.num_want = 0;

		TORRENT_ASSERT(!m_abort || req.event == tracker_request::stopped);
		if (m_abort && req.event != tracker_request::stopped)
			return;

		std::string protocol = req.url.substr(0, req.url.find(':'));

		boost::intrusive_ptr<tracker_connection> con;

#ifdef TORRENT_USE_OPENSSL
		if (protocol == "http" || protocol == "https")
#else
		if (protocol == "http")
#endif
		{
			con = new http_tracker_connection(
				ios, cc, *this, req, c
				, m_ses, m_proxy, auth
#if TORRENT_USE_I2P
				, &m_ses.m_i2p_conn
#endif
				);
		}
		else if (protocol == "udp")
		{
			con = new udp_tracker_connection(
				ios, cc, *this, req , c, m_ses
				, m_proxy);
		}
		else
		{
			// we need to post the error to avoid deadlock
			if (boost::shared_ptr<request_callback> r = c.lock())
				ios.post(boost::bind(&request_callback::tracker_request_error, r, req
					, -1, error_code(errors::unsupported_url_protocol)
					, "", 0));
			return;
		}

		m_connections.push_back(con);

		boost::shared_ptr<request_callback> cb = con->requester();
		if (cb) cb->m_manager = this;
		con->start();
	}
开发者ID:milindbenjamin,项目名称:libtorrent-android,代码行数:58,代码来源:tracker_manager.cpp

示例4: queue_request

	void tracker_manager::queue_request(
		io_service& ios
		, tracker_request req
		, std::weak_ptr<request_callback> c)
	{
		TORRENT_ASSERT(is_single_thread());
		TORRENT_ASSERT(req.num_want >= 0);
		TORRENT_ASSERT(!m_abort || req.event == tracker_request::stopped);
		if (m_abort && req.event != tracker_request::stopped) return;
		if (req.event == tracker_request::stopped)
			req.num_want = 0;

		TORRENT_ASSERT(!m_abort || req.event == tracker_request::stopped);
		if (m_abort && req.event != tracker_request::stopped)
			return;

		std::string protocol = req.url.substr(0, req.url.find(':'));

#ifdef TORRENT_USE_OPENSSL
		if (protocol == "http" || protocol == "https")
#else
		if (protocol == "http")
#endif
		{
			std::shared_ptr<http_tracker_connection> con
				= std::make_shared<http_tracker_connection>(
					std::ref(ios), std::ref(*this), std::cref(req), c);
			m_http_conns.push_back(con);
			con->start();
			return;
		}
		else if (protocol == "udp")
		{
			std::shared_ptr<udp_tracker_connection> con
				= std::make_shared<udp_tracker_connection>(
					std::ref(ios), std::ref(*this), std::cref(req) , c);
			m_udp_conns[con->transaction_id()] = con;
			con->start();
			return;
		}

		// we need to post the error to avoid deadlock
		if (std::shared_ptr<request_callback> r = c.lock())
			ios.post(std::bind(&request_callback::tracker_request_error, r, req
				, -1, error_code(errors::unsupported_url_protocol)
				, "", 0));
	}
开发者ID:Chocobo1,项目名称:libtorrent,代码行数:47,代码来源:tracker_manager.cpp

示例5: read_send

void read_send( session_ptr session ) {
	string read;
	cin >> read;
	if( read == "quit" )
	{
		// session_->close();
		return ;
	}

	cout << "[SYS:send]" << read << endl;
	char send_buf[1024] = {0};
	unsigned short message_len = static_cast<unsigned short>( read.length() );
	::memcpy( send_buf, &message_len, sizeof(message_len) );
	::memcpy( send_buf + sizeof(message_len), read.c_str(), message_len );

	ios_.post(
		BOOST_BIND( 
			&io_session::write, session,
			shared_ptr<io_buffer>( new io_buffer( send_buf, message_len + sizeof(message_len)))
			)
		);
//	session->write( shared_ptr<io_buffer>( new io_buffer( send_buf, message_len + sizeof(message_len))) );
}
开发者ID:jerky168,项目名称:fastnetwork,代码行数:23,代码来源:client.cpp

示例6: postNewValue

void postNewValue (io_service & ios, newValFunc_t f, Tag & t, const string& nam, const any& val, Variable::Pointer var  )
{
  ios.post( bind(f, std::ref(t), nam, val, var) );
}
开发者ID:skifcorp,项目名称:amigo,代码行数:4,代码来源:prot.cpp

示例7: do_sendto

///sendto 发送信息到目的用户端
void talk_to_svr::do_sendto(const std::string &username, const std::string &msg)
{
    //username 和 msg 赋值
    std::string writeMsg("send to " + username + " " + msg + "\n");
    service.post(MEM_FN1(do_write, writeMsg));
}
开发者ID:coderdeng,项目名称:net_code,代码行数:7,代码来源:asyncClient.cpp

示例8: do_ask_clients

///ask for clients 亲求客户端信息
void talk_to_svr::do_ask_clients()
{
    service.post(MEM_FN1(do_write, "ask for clients\n"));
}
开发者ID:coderdeng,项目名称:net_code,代码行数:5,代码来源:asyncClient.cpp

示例9: do_ping

///ping,发送ping请求给服务器
void talk_to_svr::do_ping()
{
    service.post(MEM_FN1(do_write, "ping\n"));
}
开发者ID:coderdeng,项目名称:net_code,代码行数:5,代码来源:asyncClient.cpp


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