fixed web server tests to not require a fixed port. Should be much more likely to pass now
This commit is contained in:
@@ -341,7 +341,7 @@ boost::shared_ptr<libtorrent::thread> web_server;
|
||||
libtorrent::mutex web_lock;
|
||||
libtorrent::condition web_initialized;
|
||||
|
||||
void stop_web_server(int port)
|
||||
void stop_web_server()
|
||||
{
|
||||
if (web_server && web_ios)
|
||||
{
|
||||
@@ -352,19 +352,20 @@ void stop_web_server(int port)
|
||||
}
|
||||
}
|
||||
|
||||
void web_server_thread(int port, bool ssl);
|
||||
void web_server_thread(int* port, bool ssl);
|
||||
|
||||
void start_web_server(int port, bool ssl)
|
||||
int start_web_server(bool ssl)
|
||||
{
|
||||
stop_web_server(port);
|
||||
stop_web_server();
|
||||
|
||||
{
|
||||
mutex::scoped_lock l(web_lock);
|
||||
web_initialized.clear(l);
|
||||
}
|
||||
|
||||
fprintf(stderr, "starting web server on port %d\n", port);
|
||||
web_server.reset(new libtorrent::thread(boost::bind(&web_server_thread, port, ssl)));
|
||||
int port = 0;
|
||||
|
||||
web_server.reset(new libtorrent::thread(boost::bind(&web_server_thread, &port, ssl)));
|
||||
|
||||
{
|
||||
mutex::scoped_lock l(web_lock);
|
||||
@@ -376,6 +377,7 @@ void start_web_server(int port, bool ssl)
|
||||
error_code ec;
|
||||
create_directory("relative", ec);
|
||||
test_sleep(100);
|
||||
return port;
|
||||
}
|
||||
|
||||
void send_response(stream_socket& s, error_code& ec
|
||||
@@ -409,7 +411,7 @@ void on_accept(error_code const& ec)
|
||||
}
|
||||
}
|
||||
|
||||
void web_server_thread(int port, bool ssl)
|
||||
void web_server_thread(int* port, bool ssl)
|
||||
{
|
||||
// TODO: support SSL
|
||||
|
||||
@@ -432,14 +434,15 @@ void web_server_thread(int port, bool ssl)
|
||||
web_initialized.signal(l);
|
||||
return;
|
||||
}
|
||||
acceptor.bind(tcp::endpoint(address_v4::any(), port), ec);
|
||||
acceptor.bind(tcp::endpoint(address_v4::any(), 0), ec);
|
||||
if (ec)
|
||||
{
|
||||
fprintf(stderr, "Error binding listen socket to port %d: %s\n", port, ec.message().c_str());
|
||||
fprintf(stderr, "Error binding listen socket to port 0: %s\n", ec.message().c_str());
|
||||
mutex::scoped_lock l(web_lock);
|
||||
web_initialized.signal(l);
|
||||
return;
|
||||
}
|
||||
*port = acceptor.local_endpoint().port();
|
||||
acceptor.listen(10, ec);
|
||||
if (ec)
|
||||
{
|
||||
@@ -451,7 +454,7 @@ void web_server_thread(int port, bool ssl)
|
||||
|
||||
web_ios = &ios;
|
||||
|
||||
fprintf(stderr, "web server initialized on port %d\n", port);
|
||||
fprintf(stderr, "web server initialized on port %d\n", *port);
|
||||
|
||||
{
|
||||
mutex::scoped_lock l(web_lock);
|
||||
@@ -590,7 +593,11 @@ void web_server_thread(int port, bool ssl)
|
||||
snprintf(eh, sizeof(eh), "%sContent-Range: bytes %d-%d\r\n"
|
||||
, extra_header ? extra_header : "", start, end);
|
||||
send_response(s, ec, 206, "Partial", eh, end - start + 1);
|
||||
write(s, boost::asio::buffer(&file_buf[0] + start, end - start + 1), boost::asio::transfer_all(), ec);
|
||||
if (!file_buf.empty())
|
||||
{
|
||||
write(s, boost::asio::buffer(&file_buf[0] + start, end - start + 1)
|
||||
, boost::asio::transfer_all(), ec);
|
||||
}
|
||||
// fprintf(stderr, "send %d bytes of payload\n", end - start + 1);
|
||||
}
|
||||
else
|
||||
|
Reference in New Issue
Block a user