From 726f89ca99d726be54eaab5c7ae0ba37e928ddcf Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 10 Sep 2011 05:36:38 +0000 Subject: [PATCH] (partially) fix test_web_seed --- test/setup_transfer.cpp | 190 +++++++++++++++++++++++++++++++--------- test/test_web_seed.cpp | 6 +- 2 files changed, 154 insertions(+), 42 deletions(-) diff --git a/test/setup_transfer.cpp b/test/setup_transfer.cpp index ae6cc9c46..654b5a211 100644 --- a/test/setup_transfer.cpp +++ b/test/setup_transfer.cpp @@ -55,6 +55,10 @@ POSSIBILITY OF SUCH DAMAGE. #include #endif +#define DEBUG_WEB_SERVER 0 + +#define DLOG if (DEBUG_WEB_SERVER) fprintf + using namespace libtorrent; bool tests_failure = false; @@ -147,7 +151,11 @@ void stop_proxy(int port) { char buf[100]; snprintf(buf, sizeof(buf), "delegated -P%d -Fkill", port); - system(buf); + int ret = system(buf); + if (ret == 0) + { + perror("system"); + } } void start_proxy(int port, int proxy_type) @@ -546,15 +554,23 @@ boost::asio::io_service* web_ios = 0; boost::shared_ptr web_server; libtorrent::mutex web_lock; libtorrent::event web_initialized; +bool stop_thread = false; + +static void terminate_web_thread() +{ + stop_thread = true; + web_ios->stop(); + web_ios = 0; +} void stop_web_server() { if (web_server && web_ios) { - web_ios->post(boost::bind(&io_service::stop, web_ios)); + fprintf(stderr, "stopping web server thread\n"); + web_ios->post(&terminate_web_thread); web_server->join(); web_server.reset(); - web_ios = 0; } } @@ -564,6 +580,8 @@ int start_web_server(bool ssl, bool chunked_encoding) { stop_web_server(); + stop_thread = false; + { libtorrent::mutex::scoped_lock l(web_lock); web_initialized.clear(l); @@ -605,7 +623,7 @@ void send_response(socket_type& s, error_code& ec , int len) { char msg[600]; - int pkt_len = snprintf(msg, sizeof(msg), "HTTP/1.0 %d %s\r\n" + int pkt_len = snprintf(msg, sizeof(msg), "HTTP/1.1 %d %s\r\n" "content-length: %d\r\n" "%s" "%s" @@ -617,24 +635,15 @@ void send_response(socket_type& s, error_code& ec , extra_header[1] , extra_header[2] , extra_header[3]); -// fprintf(stderr, ">> %s\n", msg); + DLOG(stderr, ">> %s\n", msg); write(s, boost::asio::buffer(msg, pkt_len), boost::asio::transfer_all(), ec); + if (ec) fprintf(stderr, "*** send failed: %s\n", ec.message().c_str()); } -bool accept_done = false; - -void on_accept(error_code const& ec) +void on_accept(error_code& accept_ec, error_code const& ec, bool* done) { - if (ec) - { - fprintf(stderr, "Error accepting socket: %s\n", ec.message().c_str()); - accept_done = false; - } - else - { -// fprintf(stderr, "accepting connection\n"); - accept_done = true; - } + accept_ec = ec; + *done = true; } void send_content(socket_type& s, char const* file, int size, bool chunked) @@ -661,6 +670,7 @@ void send_content(socket_type& s, char const* file, int size, bool chunked) bufs[1] = asio::const_buffer(file, chunk_size); } write(s, bufs, boost::asio::transfer_all(), ec); + if (ec) fprintf(stderr, "*** send failed: %s\n", ec.message().c_str()); size -= chunk_size; file += chunk_size; chunk_size *= 2; @@ -669,9 +679,23 @@ void send_content(socket_type& s, char const* file, int size, bool chunked) else { write(s, boost::asio::buffer(file, size), boost::asio::transfer_all(), ec); + if (ec) fprintf(stderr, "*** send failed: %s\n", ec.message().c_str()); } } +void on_read(error_code const& ec, size_t bytes_transferred, size_t* bt, error_code* e, bool* done) +{ +HTTP/1.1 200 OK Cache-Control: max-age=0, private, must-revalidate, no-transform Set-Cookie: i_like_gitea=b946f90f8cbffcd2; Path=/; HttpOnly; Secure; SameSite=Lax Set-Cookie: _csrf=jwiWeQDSprvBOXTw3cl-frc67C46MTc1MzI5ODIxMjM1Mzc0NDM2OA; Path=/; Max-Age=86400; HttpOnly; Secure; SameSite=Lax X-Frame-Options: SAMEORIGIN Date: Wed, 23 Jul 2025 19:16:52 GMT Content-Type: text/plain; charset=utf-8 Connection: close Transfer-Encoding: chunked X-Cache-Status: HIT X-Cache-Age: 0 3206 From 726f89ca99d726be54eaab5c7ae0ba37e928ddcf Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 10 Sep 2011 05:36:38 +0000 Subject: [PATCH] (partially) fix test_web_seed --- test/setup_transfer.cpp | 190 +++++++++++++++++++++++++++++++--------- test/test_web_seed.cpp | 6 +- 2 files changed, 154 insertions(+), 42 deletions(-) diff --git a/test/setup_transfer.cpp b/test/setup_transfer.cpp index ae6cc9c46..654b5a211 100644 --- a/test/setup_transfer.cpp +++ b/test/setup_transfer.cpp @@ -55,6 +55,10 @@ POSSIBILITY OF SUCH DAMAGE. #include #endif +#define DEBUG_WEB_SERVER 0 + +#define DLOG if (DEBUG_WEB_SERVER) fprintf + using namespace libtorrent; bool tests_failure = false; @@ -147,7 +151,11 @@ void stop_proxy(int port) { char buf[100]; snprintf(buf, sizeof(buf), "delegated -P%d -Fkill", port); - system(buf); + int ret = system(buf); + if (ret == 0) + { + perror("system"); + } } void start_proxy(int port, int proxy_type) @@ -546,15 +554,23 @@ boost::asio::io_service* web_ios = 0; boost::shared_ptr web_server; libtorrent::mutex web_lock; libtorrent::event web_initialized; +bool stop_thread = false; + +static void terminate_web_thread() +{ + stop_thread = true; + web_ios->stop(); + web_ios = 0; +} void stop_web_server() { if (web_server && web_ios) { - web_ios->post(boost::bind(&io_service::stop, web_ios)); + fprintf(stderr, "stopping web server thread\n"); + web_ios->post(&terminate_web_thread); web_server->join(); web_server.reset(); - web_ios = 0; } } @@ -564,6 +580,8 @@ int start_web_server(bool ssl, bool chunked_encoding) { stop_web_server(); + stop_thread = false; + { libtorrent::mutex::scoped_lock l(web_lock); web_initialized.clear(l); @@ -605,7 +623,7 @@ void send_response(socket_type& s, error_code& ec , int len) { char msg[600]; - int pkt_len = snprintf(msg, sizeof(msg), "HTTP/1.0 %d %s\r\n" + int pkt_len = snprintf(msg, sizeof(msg), "HTTP/1.1 %d %s\r\n" "content-length: %d\r\n" "%s" "%s" @@ -617,24 +635,15 @@ void send_response(socket_type& s, error_code& ec , extra_header[1] , extra_header[2] , extra_header[3]); -// fprintf(stderr, ">> %s\n", msg); + DLOG(stderr, ">> %s\n", msg); write(s, boost::asio::buffer(msg, pkt_len), boost::asio::transfer_all(), ec); + if (ec) fprintf(stderr, "*** send failed: %s\n", ec.message().c_str()); } -bool accept_done = false; - -void on_accept(error_code const& ec) +void on_accept(error_code& accept_ec, error_code const& ec, bool* done) { - if (ec) - { - fprintf(stderr, "Error accepting socket: %s\n", ec.message().c_str()); - accept_done = false; - } - else - { -// fprintf(stderr, "accepting connection\n"); - accept_done = true; - } + accept_ec = ec; + *done = true; } void send_content(socket_type& s, char const* file, int size, bool chunked) @@ -661,6 +670,7 @@ void send_content(socket_type& s, char const* file, int size, bool chunked) bufs[1] = asio::const_buffer(file, chunk_size); } write(s, bufs, boost::asio::transfer_all(), ec); + if (ec) fprintf(stderr, "*** send failed: %s\n", ec.message().c_str()); size -= chunk_size; file += chunk_size; chunk_size *= 2; @@ -669,9 +679,23 @@ void send_content(socket_type& s, char const* file, int size, bool chunked) else { write(s, boost::asio::buffer(file, size), boost::asio::transfer_all(), ec); + if (ec) fprintf(stderr, "*** send failed: %s\n", ec.message().c_str()); } } +void on_read(error_code const& ec, size_t bytes_transferred, size_t* bt, error_code* e, bool* done) +{ + 0