Skip to content

Commit 03dddb2

Browse files
committed
Removed noexcept from destructors; added some flags for chunked transfer and timeouts.
1 parent 47ced49 commit 03dddb2

File tree

3 files changed

+48
-15
lines changed

3 files changed

+48
-15
lines changed

http/src/http/v2/client/client.cpp

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,22 @@ struct request_context {
3434
boost::asio::streambuf request_buffer_;
3535
boost::asio::streambuf response_buffer_;
3636

37+
// TODO configure chunked transfer encoding
38+
bool chunked_;
39+
3740
// TODO configure deadline timer for timeouts
41+
bool timedout_;
3842

3943
std::uint64_t total_bytes_written_, total_bytes_read_;
4044

4145
request_context(std::shared_ptr<client_connection::async_connection> connection,
42-
request request,
43-
request_options options)
46+
request request,
47+
request_options options)
4448
: connection_(connection)
4549
, request_(request)
4650
, options_(options)
51+
, chunked_(false)
52+
, timedout_(false)
4753
, total_bytes_written_(0)
4854
, total_bytes_read_(0) { }
4955

@@ -57,7 +63,7 @@ struct client::impl {
5763
std::unique_ptr<client_connection::async_connection> mock_connection,
5864
client_options options);
5965

60-
~impl() noexcept;
66+
~impl();
6167

6268
std::future<response> execute(std::shared_ptr<request_context> context);
6369

@@ -68,6 +74,10 @@ struct client::impl {
6874
void write_request(const boost::system::error_code &ec,
6975
std::shared_ptr<request_context> context);
7076

77+
void write_body(const boost::system::error_code &ec,
78+
std::size_t bytes_written,
79+
std::shared_ptr<request_context> context);
80+
7181
void read_response(const boost::system::error_code &ec,
7282
std::size_t bytes_written,
7383
std::shared_ptr<request_context> context);
@@ -117,7 +127,7 @@ client::impl::impl(std::unique_ptr<client_connection::async_resolver> mock_resol
117127

118128
}
119129

120-
client::impl::~impl() noexcept {
130+
client::impl::~impl() {
121131
sentinel_.reset();
122132
lifetime_thread_.join();
123133
}
@@ -186,14 +196,37 @@ void client::impl::write_request(const boost::system::error_code &ec,
186196
context->response_promise_.set_exception(std::make_exception_ptr(client_exception(client_error::invalid_request)));
187197
}
188198

199+
context->connection_->async_write(context->request_buffer_,
200+
strand_.wrap([=] (const boost::system::error_code &ec,
201+
std::size_t bytes_written) {
202+
write_body(ec, bytes_written, context);
203+
}));
204+
}
205+
206+
void client::impl::write_body(const boost::system::error_code &ec,
207+
std::size_t bytes_written,
208+
std::shared_ptr<request_context> context) {
209+
if (ec) {
210+
context->response_promise_.set_exception(std::make_exception_ptr(std::system_error(ec.value(), std::system_category())));
211+
return;
212+
}
213+
214+
context->total_bytes_written_ += bytes_written;
215+
if (auto progress = context->options_.progress()) {
216+
progress(client_message::transfer_direction::bytes_written, context->total_bytes_written_);
217+
}
218+
219+
std::ostream request_stream(&context->request_buffer_);
189220
// TODO write payload to request_buffer_
221+
if (!request_stream) {
222+
context->response_promise_.set_exception(std::make_exception_ptr(client_exception(client_error::invalid_request)));
223+
}
190224

191225
context->connection_->async_write(context->request_buffer_,
192-
strand_.wrap([=] (const boost::system::error_code &ec,
193-
std::size_t bytes_written) {
194-
// TODO write chunked or write body
195-
read_response(ec, bytes_written, context);
196-
}));
226+
strand_.wrap([=] (const boost::system::error_code &ec,
227+
std::size_t bytes_written) {
228+
read_response(ec, bytes_written, context);
229+
}));
197230
}
198231

199232
void client::impl::read_response(const boost::system::error_code &ec,
@@ -335,7 +368,7 @@ client::client(std::unique_ptr<client_connection::async_resolver> mock_resolver,
335368

336369
}
337370

338-
client::~client() noexcept {
371+
client::~client() {
339372
delete pimpl_;
340373
}
341374

http/src/network/http/v2/client/client.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class client_options {
9595
/**
9696
* \brief Destructor.
9797
*/
98-
~client_options() noexcept {
98+
~client_options() {
9999

100100
}
101101

@@ -316,7 +316,7 @@ class client {
316316
/**
317317
* \brief Destructor.
318318
*/
319-
~client() noexcept;
319+
~client();
320320

321321
/**
322322
* \brief Executes an HTTP request.

http/src/network/http/v2/client/request.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class request_options {
8888
/**
8989
* \brief Destructor.
9090
*/
91-
~request_options() noexcept {
91+
~request_options() {
9292

9393
}
9494

@@ -184,7 +184,7 @@ class byte_source {
184184
/**
185185
* \brief Destructor.
186186
*/
187-
virtual ~byte_source() noexcept {}
187+
virtual ~byte_source() {}
188188

189189
/**
190190
* \brief Allows the request to read the data into a local
@@ -342,7 +342,7 @@ class request {
342342
/**
343343
* \brief Destructor.
344344
*/
345-
~request() noexcept {
345+
~request() {
346346

347347
}
348348

0 commit comments

Comments
 (0)