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


C++ error_code::message方法代码示例

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


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

示例1: handle_write

void connection::handle_write(const error_code& e, reply *rep)
{
    //如果连接已经断开 则放弃写回
    if(stopped())return;
    string mess_r = "Client[" + address_ + ":" + port_ + "] request file " + request_.uri;
    //记录 请求信息
    log->record(mess_r);
    if (!e)
    {
        // Initiate graceful connection closure.
        //error_code ignored_ec;
        //socket_.shutdown(asio::ip::tcp::socket::shutdown_both, ignored_ec);
	
	    string mess_s;
	    if(rep->status == reply::ok){
		    mess_s = "Successfully send file " + request_.uri + " with " + boost::lexical_cast<std::string>(rep->content.size())+ " bytes to clien[" +\
					 address_ + ":" + port_ + "]";
	    }else{
		    mess_s = "Failed to send file " + request_.uri + " to client[" + address_ + ":" + port_ + "] due to " + rep->to_string(rep->status);
	    }
	    log->record(mess_s);
        connection::start_read();
    }else{
  	    string mess_f = "Failed to send file " + request_.uri + " to client[" + address_ + ":" + port_  + "] due to error " + e.message() ;
	    log->record(mess_f);
    }
    //connection::start_read();
    // 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:zhaoxiaohui,项目名称:server,代码行数:32,代码来源:connection.cpp

示例2: on_reply

void natpmp::on_reply(error_code const& e
	, std::size_t bytes_transferred)
{
	mutex::scoped_lock l(m_mutex);

#if defined TORRENT_ASIO_DEBUGGING
	complete_async("natpmp::on_reply");
#endif

	using namespace libtorrent::detail;
	if (e)
	{
		char msg[200];
		snprintf(msg, sizeof(msg), "error on receiving reply: %s"
			, convert_from_native(e.message()).c_str());
		log(msg, l);
		return;
	}

#if defined TORRENT_ASIO_DEBUGGING
	add_outstanding_async("natpmp::on_reply");
#endif
	// make a copy of the response packet buffer
	// to avoid overwriting it in the next receive call
	char msg_buf[16];
	memcpy(msg_buf, m_response_buffer, bytes_transferred);

	m_socket.async_receive_from(asio::buffer(&m_response_buffer, 16)
		, m_remote, boost::bind(&natpmp::on_reply, self(), _1, _2));

	// simulate packet loss
/*
	if ((random() % 2) == 0)
	{
		log(" simulating drop", l);
		return;
	}
*/
	if (m_remote != m_nat_endpoint)
	{
		char msg[200];
		snprintf(msg, sizeof(msg), "received packet from wrong IP: %s"
			, print_endpoint(m_remote).c_str());
		log(msg, l);
		return;
	}

	error_code ec;
	m_send_timer.cancel(ec);

	if (bytes_transferred < 12)
	{
		char msg[200];
		snprintf(msg, sizeof(msg), "received packet of invalid size: %d", int(bytes_transferred));
		log(msg, l);
		return;
	}

	char* in = msg_buf;
	int version = read_uint8(in);
	int cmd = read_uint8(in);
	int result = read_uint16(in);
	int time = read_uint32(in);

	if (cmd == 128)
	{
		// public IP request response
		m_external_ip = read_v4_address(in);

		char msg[200];
		snprintf(msg, sizeof(msg), "<== public IP address [ %s ]", print_address(m_external_ip).c_str());
		log(msg, l);
		return;

	}

	if (bytes_transferred < 16)
	{
		char msg[200];
		snprintf(msg, sizeof(msg), "received packet of invalid size: %d", int(bytes_transferred));
		log(msg, l);
		return;
	}

	int private_port = read_uint16(in);
	int public_port = read_uint16(in);
	int lifetime = read_uint32(in);

	(void)time; // to remove warning

	int protocol = (cmd - 128 == 1)?udp:tcp;

	char msg[200];
	int num_chars = snprintf(msg, sizeof(msg), "<== port map ["
		" protocol: %s local: %u external: %u ttl: %u ]"
		, (cmd - 128 == 1 ? "udp" : "tcp")
		, private_port, public_port, lifetime);

	if (version != 0)
	{
//.........这里部分代码省略.........
开发者ID:caisan,项目名称:libtorrent,代码行数:101,代码来源:natpmp.cpp

示例3: on_disconnected

 void on_disconnected(error_code const& ec)      
 {
     LogInfo("Client " << " disconnected with error: " << ec.message() );
 }
开发者ID:wangfeilong321,项目名称:test_osg,代码行数:4,代码来源:visapp3.cpp

示例4: on_reply

void natpmp::on_reply(error_code const& e
	, std::size_t bytes_transferred)
{
	TORRENT_ASSERT(is_single_thread());

	COMPLETE_ASYNC("natpmp::on_reply");

	using namespace libtorrent::detail;
	if (e)
	{
#ifndef TORRENT_DISABLE_LOGGING
		log("error on receiving reply: %s"
			, convert_from_native(e.message()).c_str());
#endif
		return;
	}

	ADD_OUTSTANDING_ASYNC("natpmp::on_reply");
	// make a copy of the response packet buffer
	// to avoid overwriting it in the next receive call
	char msg_buf[sizeof(m_response_buffer)];
	memcpy(msg_buf, m_response_buffer, bytes_transferred);

	m_socket.async_receive_from(boost::asio::buffer(&m_response_buffer[0]
		, sizeof(m_response_buffer))
		, m_remote, std::bind(&natpmp::on_reply, self(), _1, _2));

	if (m_remote != m_nat_endpoint)
	{
#ifndef TORRENT_DISABLE_LOGGING
		log("received packet from wrong IP: %s"
			, print_endpoint(m_remote).c_str());
#endif
		return;
	}

	error_code ec;
	m_send_timer.cancel(ec);

	if (bytes_transferred < 12)
	{
#ifndef TORRENT_DISABLE_LOGGING
		log("received packet of invalid size: %d", int(bytes_transferred));
#endif
		return;
	}

	char* in = msg_buf;
	int version = read_uint8(in);
	int cmd = read_uint8(in);
	int result = read_uint16(in);
	int time = read_uint32(in);
	TORRENT_UNUSED(version);
	TORRENT_UNUSED(time);

	if (cmd == 128)
	{
		// public IP request response
		m_external_ip = read_v4_address(in);

#ifndef TORRENT_DISABLE_LOGGING
		log("<== public IP address [ %s ]", print_address(m_external_ip).c_str());
#endif
		return;

	}

	if (bytes_transferred != 16)
	{
#ifndef TORRENT_DISABLE_LOGGING
		log("received packet of invalid size: %d", int(bytes_transferred));
#endif
		return;
	}

	int const private_port = read_uint16(in);
	int const public_port = read_uint16(in);
	int const lifetime = read_uint32(in);

	int const protocol = (cmd - 128 == 1)?udp:tcp;

#ifndef TORRENT_DISABLE_LOGGING
	char msg[200];
	int num_chars = std::snprintf(msg, sizeof(msg), "<== port map ["
		" protocol: %s local: %u external: %u ttl: %u ]"
		, (cmd - 128 == 1 ? "udp" : "tcp")
		, private_port, public_port, lifetime);

	if (version != 0)
	{
		std::snprintf(msg + num_chars, sizeof(msg) - num_chars, "unexpected version: %u"
			, version);
		log("%s", msg);
	}
#endif

	mapping_t* m = nullptr;
	int index = -1;
	for (std::vector<mapping_t>::iterator i = m_mappings.begin()
		, end(m_mappings.end()); i != end; ++i)
//.........这里部分代码省略.........
开发者ID:RealImage,项目名称:libtorrent,代码行数:101,代码来源:natpmp.cpp

示例5: handleResolve

void TAsyncCommonSocketChannel::handleResolve(const error_code& err,
        tcp::resolver::iterator epItr, const ReturnCallback& cb) {
    if (err) {
        cb(::boost::make_shared<TTransportException>("TAsyncCommonSocketChannel error in handling resolve: " + err.message()));
    } else {
        //attempt a connection on the first endpoint resolved
        connectToResolvedEndpoint(epItr, cb);
    }
}
开发者ID:crawlik,项目名称:ezbake-common-cpp,代码行数:9,代码来源:TAsyncCommonSocketChannel.cpp

示例6: on_receive

	void http_seed_connection::on_receive(error_code const& error
		, std::size_t bytes_transferred)
	{
		INVARIANT_CHECK;

		if (error)
		{
			m_statistics.received_bytes(0, bytes_transferred);
#ifdef TORRENT_VERBOSE_LOGGING
			peer_log("*** http_seed_connection error: %s", error.message().c_str());
#endif
			return;
		}

		boost::shared_ptr<torrent> t = associated_torrent().lock();
		TORRENT_ASSERT(t);

		for (;;)
		{
			buffer::const_interval recv_buffer = receive_buffer();

			if (bytes_transferred == 0) break;
			TORRENT_ASSERT(recv_buffer.left() > 0);

			TORRENT_ASSERT(!m_requests.empty());
			if (m_requests.empty())
			{
				m_statistics.received_bytes(0, bytes_transferred);
				disconnect(errors::http_error, 2);
				return;
			}

			peer_request front_request = m_requests.front();

			bool header_finished = m_parser.header_finished();
			if (!header_finished)
			{
				bool parse_error = false;
				int protocol = 0;
				int payload = 0;
				boost::tie(payload, protocol) = m_parser.incoming(recv_buffer, parse_error);
				m_statistics.received_bytes(0, protocol);
				bytes_transferred -= protocol;
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
				if (payload > front_request.length) payload = front_request.length;
#endif

				if (parse_error)
				{
					m_statistics.received_bytes(0, bytes_transferred);
					disconnect(errors::http_parse_error, 2);
					return;
				}

				TORRENT_ASSERT(recv_buffer.left() == 0 || *recv_buffer.begin == 'H');
			
				TORRENT_ASSERT(recv_buffer.left() <= packet_size());
				
				// this means the entire status line hasn't been received yet
				if (m_parser.status_code() == -1)
				{
					TORRENT_ASSERT(payload == 0);
					TORRENT_ASSERT(bytes_transferred == 0);
					break;
				}

				// if the status code is not one of the accepted ones, abort
				if (!is_ok_status(m_parser.status_code()))
				{
					int retry_time = atoi(m_parser.header("retry-after").c_str());
					if (retry_time <= 0) retry_time = 5 * 60;
					// temporarily unavailable, retry later
					t->retry_web_seed(this, retry_time);

					std::string error_msg = to_string(m_parser.status_code()).elems
						+ (" " + m_parser.message());
					if (m_ses.m_alerts.should_post<url_seed_alert>())
					{
						m_ses.m_alerts.post_alert(url_seed_alert(t->get_handle(), url()
							, error_msg));
					}
					m_statistics.received_bytes(0, bytes_transferred);
					disconnect(error_code(m_parser.status_code(), get_http_category()), 1);
					return;
				}
				if (!m_parser.header_finished())
				{
					TORRENT_ASSERT(payload == 0);
					TORRENT_ASSERT(bytes_transferred == 0);
					break;
				}
			}

			// we just completed reading the header
			if (!header_finished)
			{
				if (is_redirect(m_parser.status_code()))
				{
					// this means we got a redirection request
					// look for the location header
//.........这里部分代码省略.........
开发者ID:52M,项目名称:twister-core,代码行数:101,代码来源:http_seed_connection.cpp

示例7: on_udp_receive

	void on_udp_receive(error_code const& ec, size_t bytes_transferred, udp::endpoint* from, char* buffer, int size)
	{
		if (ec)
		{
			fprintf(stderr, "%s: UDP tracker, read failed: %s\n", time_now_string(), ec.message().c_str());
			return;
		}

		if (bytes_transferred < 16)
		{
			fprintf(stderr, "%s: UDP message too short (from: %s)\n", time_now_string(), print_endpoint(*from).c_str());
			return;
		}

		fprintf(stderr, "%s: UDP message %d bytes\n", time_now_string(), int(bytes_transferred));

		char* ptr = buffer;
		detail::read_uint64(ptr);
		boost::uint32_t action = detail::read_uint32(ptr);
		boost::uint32_t transaction_id = detail::read_uint32(ptr);

		error_code e;

		switch (action)
		{
			case 0: // connect

				fprintf(stderr, "%s: UDP connect from %s\n", time_now_string()
					, print_endpoint(*from).c_str());
				ptr = buffer;
				detail::write_uint32(0, ptr); // action = connect
				detail::write_uint32(transaction_id, ptr); // transaction_id
				detail::write_uint64(10, ptr); // connection_id
				m_socket.send_to(asio::buffer(buffer, 16), *from, 0, e);
				if (e) fprintf(stderr, "%s: UDP send_to failed. ERROR: %s\n"
					, time_now_string(), e.message().c_str());
				else fprintf(stderr, "%s: UDP sent response to: %s\n"
					, time_now_string(), print_endpoint(*from).c_str());
				break;

			case 1: // announce

				++m_udp_announces;
				fprintf(stderr, "%s: UDP announce [%d]\n", time_now_string()
					, int(m_udp_announces));
				ptr = buffer;
				detail::write_uint32(1, ptr); // action = announce
				detail::write_uint32(transaction_id, ptr); // transaction_id
				detail::write_uint32(1800, ptr); // interval
				detail::write_uint32(1, ptr); // incomplete
				detail::write_uint32(1, ptr); // complete
				// 0 peers
				m_socket.send_to(asio::buffer(buffer, 20), *from, 0, e);
				if (e) fprintf(stderr, "%s: UDP send_to failed. ERROR: %s\n"
					, time_now_string(), e.message().c_str());
				else fprintf(stderr, "%s: UDP sent response to: %s\n"
					, time_now_string(), print_endpoint(*from).c_str());
				break;
			case 2:
				// ignore scrapes
				fprintf(stderr, "%s: UDP scrape (ignored)\n", time_now_string());
				break;
			default:
				fprintf(stderr, "%s: UDP unknown message: %d\n", time_now_string()
					, action);
				break;
		}

		m_socket.async_receive_from(
			asio::buffer(buffer, size), *from, 0
			, boost::bind(&udp_tracker::on_udp_receive, this, _1, _2, from, buffer, size));
	}
开发者ID:caisan,项目名称:libtorrent,代码行数:72,代码来源:udp_tracker.cpp

示例8: printErrorCode

void Client::printErrorCode(const error_code &ec, const std::string& method)
{
	warnlog << "[" << method << "] Error Code: " << ec.value() << ", message: " << ec.message();
}
开发者ID:wangxun159123,项目名称:Brute-Force-Game-Engine,代码行数:4,代码来源:Client.cpp

示例9: handle_sent

 void handle_sent(const error_code& ec, std::size_t) {
     // here response has been sent
     if (ec) {
         std::cout << "Error sending response to " << remote_endpoint_ << ": " << ec.message() << "\n";
     }
 }
开发者ID:CCJY,项目名称:coliru,代码行数:6,代码来源:main.cpp

示例10: on_receive

	// throws exception when the client should be disconnected
	void web_peer_connection::on_receive(error_code const& error
		, std::size_t bytes_transferred)
	{
		INVARIANT_CHECK;

		if (error)
		{
#ifdef TORRENT_VERBOSE_LOGGING
			(*m_logger) << "*** web_peer_connection error: "
				<< error.message() << "\n";
#endif
			return;
		}

		boost::shared_ptr<torrent> t = associated_torrent().lock();
		TORRENT_ASSERT(t);

		incoming_piece_fragment();

		for (;;)
		{
			buffer::const_interval recv_buffer = receive_buffer();

			int payload;
			int protocol;
			bool header_finished = m_parser.header_finished();
			if (!header_finished)
			{
				boost::tie(payload, protocol) = m_parser.incoming(recv_buffer);
				m_statistics.received_bytes(0, protocol);
				bytes_transferred -= protocol;

				TORRENT_ASSERT(recv_buffer.left() == 0 || *recv_buffer.begin == 'H');
			
				TORRENT_ASSERT(recv_buffer.left() <= packet_size());
				
				// this means the entire status line hasn't been received yet
				if (m_parser.status_code() == -1)
				{
					TORRENT_ASSERT(payload == 0);
					TORRENT_ASSERT(bytes_transferred == 0);
					break;
				}

				// if the status code is not one of the accepted ones, abort
				if (m_parser.status_code() != 206 // partial content
					&& m_parser.status_code() != 200 // OK
					&& !(m_parser.status_code() >= 300 // redirect
						&& m_parser.status_code() < 400))
				{
					if (m_parser.status_code() == 503)
					{
						// temporarily unavailable, retry later
						t->retry_url_seed(m_url);
					}
					t->remove_url_seed(m_url);
					std::string error_msg = boost::lexical_cast<std::string>(m_parser.status_code())
						+ " " + m_parser.message();
					if (m_ses.m_alerts.should_post(alert::warning))
					{
						session_impl::mutex_t::scoped_lock l(m_ses.m_mutex);
						m_ses.m_alerts.post_alert(url_seed_alert(t->get_handle(), url()
							, error_msg));
					}
					throw std::runtime_error(error_msg);
				}
				if (!m_parser.header_finished())
				{
					TORRENT_ASSERT(payload == 0);
					TORRENT_ASSERT(bytes_transferred == 0);
					break;
				}

				m_body_start = m_parser.body_start();
				m_received_body = 0;
			}

			// we just completed reading the header
			if (!header_finished)
			{
				if (m_parser.status_code() >= 300 && m_parser.status_code() < 400)
				{
					// this means we got a redirection request
					// look for the location header
					std::string location = m_parser.header("location");

					if (location.empty())
					{
						// we should not try this server again.
						t->remove_url_seed(m_url);
						throw std::runtime_error("got HTTP redirection status without location header");
					}
					
					bool single_file_request = false;
					if (!m_path.empty() && m_path[m_path.size() - 1] != '/')
						single_file_request = true;

					// add the redirected url and remove the current one
					if (!single_file_request)
//.........这里部分代码省略.........
开发者ID:svn2github,项目名称:libtorrent-rasterbar,代码行数:101,代码来源:web_peer_connection.cpp

示例11: announce_impl

void lsd::announce_impl(sha1_hash const& ih, int listen_port, bool broadcast
	, int retry_count)
{
#if TORRENT_USE_IPV6
	if (m_disabled && m_disabled6) return;
#else
	if (m_disabled) return;
#endif

	char ih_hex[41];
	to_hex((char const*)&ih[0], 20, ih_hex);
	char msg[200];

#ifndef TORRENT_DISABLE_LOGGING
	debug_log("==> LSD: ih: %s port: %u\n", ih_hex, listen_port);
#endif

	error_code ec;
	if (!m_disabled)
	{
		int msg_len = render_lsd_packet(msg, sizeof(msg), listen_port, ih_hex
			, m_cookie, "239.192.152.143");
		m_socket.send(msg, msg_len, ec, broadcast ? broadcast_socket::broadcast : 0);
		if (ec)
		{
			m_disabled = true;
#ifndef TORRENT_DISABLE_LOGGING
			debug_log("*** LSD: failed to send message: (%d) %s", ec.value()
				, ec.message().c_str());
#endif
		}
	}

#if TORRENT_USE_IPV6
	if (!m_disabled6)
	{
		int msg_len = render_lsd_packet(msg, sizeof(msg), listen_port, ih_hex
			, m_cookie, "[ff15::efc0:988f]");
		m_socket6.send(msg, msg_len, ec, broadcast ? broadcast_socket::broadcast : 0);
		if (ec)
		{
			m_disabled6 = true;
#ifndef TORRENT_DISABLE_LOGGING
			debug_log("*** LSD: failed to send message6: (%d) %s", ec.value()
				, ec.message().c_str());
#endif
		}
	}
#endif

	++retry_count;
	if (retry_count >= 3) return;

#if TORRENT_USE_IPV6
	if (m_disabled && m_disabled6) return;
#else
	if (m_disabled) return;
#endif

#if defined TORRENT_ASIO_DEBUGGING
	add_outstanding_async("lsd::resend_announce");
#endif
	m_broadcast_timer.expires_from_now(seconds(2 * retry_count), ec);
	m_broadcast_timer.async_wait(boost::bind(&lsd::resend_announce, self(), _1
		, ih, listen_port, retry_count));
}
开发者ID:caisan,项目名称:libtorrent,代码行数:66,代码来源:lsd.cpp

示例12:

static inline void print_error(char const * title, error_code const & ec)
{
	LOG_ERROR(title << ": " << ec.message());
}
开发者ID:huangyt,项目名称:MyProjects,代码行数:4,代码来源:tcp.cpp


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