Ejemplo n.º 1
0
	void thread_fun()
	{
		for (;;)
		{
			error_code ec;
			tcp::endpoint from;
			tcp::socket socket(m_ios);
			condition_variable cond;
			bool done = false;
			m_acceptor.async_accept(socket, from, boost::bind(&new_connection, _1, &ec, &done));
			while (!done)
			{
				m_ios.poll_one();
				m_ios.reset();
			}

			if (ec == boost::asio::error::operation_aborted
				|| ec == boost::asio::error::bad_descriptor) return;

			if (ec)
			{
				fprintf(stderr, "PEER Error accepting connection on peer socket: %s\n", ec.message().c_str());
				return;
			}

			fprintf(stderr, "%s: PEER incoming peer connection\n", time_now_string());
			++m_peer_requests;
			socket.close(ec);
		}
	}
Ejemplo n.º 2
0
	void thread_fun()
	{
		char buffer[2000];

		for (;;)
		{
			error_code ec;
			udp::endpoint from;
			size_t bytes_transferred;
			bool done = false;
			m_socket.async_receive_from(
				boost::asio::buffer(buffer, sizeof(buffer)), from, 0
				, boost::bind(&incoming_packet, _1, _2, &bytes_transferred, &ec, &done));
			while (!done)
			{
				m_ios.poll_one();
				m_ios.reset();
			}

			if (ec == boost::asio::error::operation_aborted
				|| ec == boost::asio::error::bad_descriptor) return;

			if (ec)
			{
				fprintf(stderr, "Error receiving on DHT socket: %s\n", ec.message().c_str());
				return;
			}

			try
			{
				entry msg = bdecode(buffer, buffer + bytes_transferred);

#if defined TORRENT_DEBUG && TORRENT_USE_IOSTREAM
				std::cerr << msg << std::endl;
#endif
				++m_dht_requests;
			}
			catch (std::exception& e)
			{
				fprintf(stderr, "failed to decode DHT message: %s\n", e.what());
			}
		}
	}
Ejemplo n.º 3
0
	void thread_fun()
	{
		char buffer[2000];

		error_code ec;
		udp::endpoint from;
		m_socket.async_receive_from(
			boost::asio::buffer(buffer, int(sizeof(buffer))), from, 0
			, std::bind(&udp_tracker::on_udp_receive, this, _1, _2, &from, &buffer[0], int(sizeof(buffer))));

		m_ios.run(ec);

		if (ec)
		{
			std::printf("UDP Error running UDP tracker service: %s\n", ec.message().c_str());
			return;
		}

		std::printf("UDP exiting UDP tracker thread\n");
	}
Ejemplo n.º 4
0
	~udp_tracker()
	{
		m_ios.post(std::bind(&udp_tracker::stop, this));
		if (m_thread) m_thread->join();
	}