- Notifications
You must be signed in to change notification settings - Fork425
Fixes #635 - bug in async server's connection read#637
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
This changes the example file server to use the read handler forPOST/PUT requests. This currently assumes that there's a content-lengthheader (not much error handling is happening here, but it's meant as aproof of concept anyway).Using this code path in an example should be good enough for the momentuntil we have better tests and a better API for this functionality.
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -378,7 +378,7 @@ struct async_connection | ||
boost::throw_exception(std::system_error(*error_encountered)); | ||
if (new_start != read_buffer_.begin()) { | ||
input_range input = | ||
boost::make_iterator_range(new_start,data_end); | ||
buffer_type::iterator start_tmp = new_start; | ||
new_start = read_buffer_.begin(); | ||
auto self = this->shared_from_this(); | ||
@@ -389,11 +389,12 @@ struct async_connection | ||
} | ||
auto self = this->shared_from_this(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. You do not need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Actually, this "self" variable makes sure that the object is alive -- it ensures that there's a shared reference in the callback that depends on the state of the connection. It's a trick that's tied to how asynchronous programming is really hard to debug. 😀 | ||
socket().async_read_some( | ||
asio::buffer(read_buffer_), | ||
strand.wrap([this, self, callback](std::error_code ec, | ||
size_t bytes_transferred) { | ||
this->wrap_read_handler(callback, ec, bytes_transferred); | ||
})); | ||
} | ||
/// Returns a reference to the underlying socket. | ||