fix linux issue in tests

This commit is contained in:
Arvid Norberg 2013-06-17 05:18:56 +00:00
parent 730fdbb978
commit 0600639b79
2 changed files with 34 additions and 3 deletions

View File

@ -86,6 +86,7 @@ struct dht_server
~dht_server()
{
m_socket.cancel();
m_socket.close();
if (m_thread) m_thread->join();
}
@ -94,6 +95,13 @@ struct dht_server
int num_hits() const { return m_dht_requests; }
static void incoming_packet(error_code const& ec, size_t bytes_transferred, size_t *ret, error_code* error, bool* done)
{
*ret = bytes_transferred;
*error = ec;
*done = true;
}
void thread_fun()
{
char buffer[2000];
@ -102,8 +110,17 @@ struct dht_server
{
error_code ec;
udp::endpoint from;
int bytes_transferred = m_socket.receive_from(
asio::buffer(buffer, sizeof(buffer)), from, 0, ec);
size_t bytes_transferred;
bool done = false;
m_socket.async_receive_from(
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;

View File

@ -92,6 +92,7 @@ struct peer_server
~peer_server()
{
m_acceptor.cancel();
m_acceptor.close();
if (m_thread) m_thread->join();
}
@ -100,6 +101,12 @@ struct peer_server
int num_hits() const { return m_peer_requests; }
static void new_connection(error_code const& ec, error_code* ret, bool* done)
{
*ret = ec;
*done = true;
}
void thread_fun()
{
for (;;)
@ -107,7 +114,14 @@ struct peer_server
error_code ec;
tcp::endpoint from;
tcp::socket socket(m_ios);
m_acceptor.accept(socket, from, ec);
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;