Fixed io_test (out of stack?), also fixed concurrent sync requests count on request error.
This commit is contained in:
parent
fd764d908c
commit
06d3c701e1
3 changed files with 20 additions and 14 deletions
|
|
@ -186,10 +186,10 @@ namespace SimpleWeb {
|
||||||
std::shared_ptr<Response> request(const std::string &method, const std::string &path = std::string("/"),
|
std::shared_ptr<Response> request(const std::string &method, const std::string &path = std::string("/"),
|
||||||
string_view content = "", const CaseInsensitiveMultimap &header = CaseInsensitiveMultimap()) {
|
string_view content = "", const CaseInsensitiveMultimap &header = CaseInsensitiveMultimap()) {
|
||||||
std::shared_ptr<Response> response;
|
std::shared_ptr<Response> response;
|
||||||
request(method, path, content, header, [&response](std::shared_ptr<Response> response_, const error_code &ec) {
|
error_code ec;
|
||||||
|
request(method, path, content, header, [&response, &ec](std::shared_ptr<Response> response_, const error_code &ec_) {
|
||||||
response = response_;
|
response = response_;
|
||||||
if(ec)
|
ec = ec_;
|
||||||
throw system_error(ec);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
@ -199,10 +199,14 @@ namespace SimpleWeb {
|
||||||
io_service->run();
|
io_service->run();
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(concurrent_synchronous_requests_mutex);
|
std::unique_lock<std::mutex> lock(concurrent_synchronous_requests_mutex);
|
||||||
if(--concurrent_synchronous_requests == 0)
|
--concurrent_synchronous_requests;
|
||||||
|
if(!concurrent_synchronous_requests)
|
||||||
io_service->reset();
|
io_service->reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(ec)
|
||||||
|
throw system_error(ec);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -212,10 +216,10 @@ namespace SimpleWeb {
|
||||||
std::shared_ptr<Response> request(const std::string &method, const std::string &path, std::istream &content,
|
std::shared_ptr<Response> request(const std::string &method, const std::string &path, std::istream &content,
|
||||||
const CaseInsensitiveMultimap &header = CaseInsensitiveMultimap()) {
|
const CaseInsensitiveMultimap &header = CaseInsensitiveMultimap()) {
|
||||||
std::shared_ptr<Response> response;
|
std::shared_ptr<Response> response;
|
||||||
request(method, path, content, header, [&response](std::shared_ptr<Response> response_, const error_code &ec) {
|
error_code ec;
|
||||||
|
request(method, path, content, header, [&response, &ec](std::shared_ptr<Response> response_, const error_code &ec_) {
|
||||||
response = response_;
|
response = response_;
|
||||||
if(ec)
|
ec = ec_;
|
||||||
throw system_error(ec);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
@ -225,10 +229,14 @@ namespace SimpleWeb {
|
||||||
io_service->run();
|
io_service->run();
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(concurrent_synchronous_requests_mutex);
|
std::unique_lock<std::mutex> lock(concurrent_synchronous_requests_mutex);
|
||||||
if(--concurrent_synchronous_requests == 0)
|
--concurrent_synchronous_requests;
|
||||||
|
if(!concurrent_synchronous_requests)
|
||||||
io_service->reset();
|
io_service->reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(ec)
|
||||||
|
throw system_error(ec);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,8 +70,8 @@ namespace SimpleWeb {
|
||||||
server_error_network_authentication_required
|
server_error_network_authentication_required
|
||||||
};
|
};
|
||||||
|
|
||||||
inline const static std::vector<std::pair<StatusCode, std::string>> &status_codes() {
|
const static std::vector<std::pair<StatusCode, std::string>> &status_codes() {
|
||||||
static std::vector<std::pair<StatusCode, std::string>> status_codes = {
|
const static std::vector<std::pair<StatusCode, std::string>> status_codes = {
|
||||||
{StatusCode::unknown, ""},
|
{StatusCode::unknown, ""},
|
||||||
{StatusCode::information_continue, "100 Continue"},
|
{StatusCode::information_continue, "100 Continue"},
|
||||||
{StatusCode::information_switching_protocols, "101 Switching Protocols"},
|
{StatusCode::information_switching_protocols, "101 Switching Protocols"},
|
||||||
|
|
|
||||||
|
|
@ -241,7 +241,6 @@ int main() {
|
||||||
vector<int> calls(100, 0);
|
vector<int> calls(100, 0);
|
||||||
vector<thread> threads;
|
vector<thread> threads;
|
||||||
for(size_t c = 0; c < 100; ++c) {
|
for(size_t c = 0; c < 100; ++c) {
|
||||||
calls[c] = 0;
|
|
||||||
threads.emplace_back([c, &client, &calls] {
|
threads.emplace_back([c, &client, &calls] {
|
||||||
client.request("GET", "/match/123", [c, &calls](shared_ptr<HttpClient::Response> response, const SimpleWeb::error_code &ec) {
|
client.request("GET", "/match/123", [c, &calls](shared_ptr<HttpClient::Response> response, const SimpleWeb::error_code &ec) {
|
||||||
assert(!ec);
|
assert(!ec);
|
||||||
|
|
@ -267,10 +266,9 @@ int main() {
|
||||||
{
|
{
|
||||||
HttpClient client("localhost:8080");
|
HttpClient client("localhost:8080");
|
||||||
{
|
{
|
||||||
vector<int> calls(100, 0);
|
vector<int> calls(2, 0);
|
||||||
vector<thread> threads;
|
vector<thread> threads;
|
||||||
for(size_t c = 0; c < 100; ++c) {
|
for(size_t c = 0; c < 2; ++c) {
|
||||||
calls[c] = 0;
|
|
||||||
threads.emplace_back([c, &client, &calls] {
|
threads.emplace_back([c, &client, &calls] {
|
||||||
try {
|
try {
|
||||||
auto r = client.request("GET", "/match/123");
|
auto r = client.request("GET", "/match/123");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue