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); } }
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()); } } }