From ea754365e607c7c36d00909ea7605daeaa64243c Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sun, 2 Jan 2011 23:10:13 +0100 Subject: Added send_data(istream). --- http_connection.cpp | 11 +++++++++++ http_connection.h | 2 ++ transcode.cpp | 11 ++--------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/http_connection.cpp b/http_connection.cpp index 128abf5..6e970b2 100644 --- a/http_connection.cpp +++ b/http_connection.cpp @@ -25,6 +25,17 @@ void HTTP::Connection::send_data(const void* data, std::size_t size) { boost::asio::write(socket, boost::asio::buffer(data, size)); } +void HTTP::Connection::send_data(std::istream& stream) { + char data[0x1000]; + std::streamsize size = 1; + while(size) { + stream.read(data, 0x1000); + size = stream.gcount(); + if(size > 0) + send_data(data, size); + } +} + HTTP::Connection::Connection(boost::asio::io_service& io_service) : socket(io_service) { headers_written = false; } diff --git a/http_connection.h b/http_connection.h index 446f0af..e3a3721 100644 --- a/http_connection.h +++ b/http_connection.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -51,6 +52,7 @@ namespace HTTP { //! Send data. void send_data(const std::string& data); void send_data(const void* data, std::size_t size); + void send_data(std::istream& stream); private: typedef std::vector > HeaderList; diff --git a/transcode.cpp b/transcode.cpp index 81d5274..f3698a3 100644 --- a/transcode.cpp +++ b/transcode.cpp @@ -13,13 +13,6 @@ void Transcoder::run() { s.push(EncoderFilter(encoder), buffer_size); s.push(DecoderFilter(decoder), buffer_size); s.push(is, buffer_size); - - char data[0x1000]; - std::streamsize size = 1; - while(size) { - s.read(data, 0x1000); - size = s.gcount(); - if(size > 0) - res->send_data(data, size); - } + + res->send_data(s); } -- cgit v1.2.3