Skip to content

Commit a8797c1

Browse files
author
Sebastiano Merlino
committed
Avoid errors when stopping the server if using internal select
1 parent 05c9c0c commit a8797c1

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed

src/webserver.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,9 +649,19 @@ bool webserver::stop()
649649
}
650650
threads.clear();
651651
typedef vector<details::daemon_item*>::const_iterator daemon_item_it;
652+
653+
if(start_method == http_utils::INTERNAL_SELECT)
654+
{
655+
for(daemon_item_it it = daemons.begin(); it != daemons.end(); ++it)
656+
MHD_quiesce_daemon((*it)->daemon);
657+
}
658+
652659
for(daemon_item_it it = daemons.begin(); it != daemons.end(); ++it)
653660
delete *it;
654661
daemons.clear();
662+
663+
shutdown(bind_socket, 2);
664+
655665
return true;
656666
}
657667
else

test/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
LDADD = $(top_builddir)/src/libhttpserver.la
2020
AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/src/httpserver/
2121
METASOURCES = AUTO
22-
check_PROGRAMS = basic http_utils
22+
check_PROGRAMS = basic http_utils threaded
2323

2424
MOSTLYCLEANFILES = *.gcda *.gcno *.gcov
2525

2626
basic_SOURCES = integ/basic.cpp
27+
threaded_SOURCES = integ/threaded.cpp
2728
http_utils_SOURCES = unit/http_utils_test.cpp
2829

2930
noinst_HEADERS = littletest.hpp

test/integ/threaded.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
This file is part of libhttpserver
3+
Copyright (C) 2011, 2012, 2013, 2014, 2015 Sebastiano Merlino
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18+
USA
19+
*/
20+
21+
#include "littletest.hpp"
22+
#include <curl/curl.h>
23+
#include <string>
24+
#include <map>
25+
#include "httpserver.hpp"
26+
27+
using namespace httpserver;
28+
using namespace std;
29+
30+
class ok_resource : public http_resource
31+
{
32+
public:
33+
void render_GET(const http_request& req, http_response** res)
34+
{
35+
*res = new http_response(http_response_builder("OK", 200, "text/plain").string_response());
36+
}
37+
};
38+
39+
LT_BEGIN_SUITE(threaded_suite)
40+
41+
webserver* ws;
42+
43+
void set_up()
44+
{
45+
ws = new webserver(create_webserver(8080).max_threads(5));
46+
ws->start(false);
47+
}
48+
49+
void tear_down()
50+
{
51+
ws->stop();
52+
delete ws;
53+
}
54+
LT_END_SUITE(threaded_suite)
55+
56+
LT_BEGIN_AUTO_TEST(threaded_suite, base)
57+
ok_resource* resource = new ok_resource();
58+
ws->register_resource("base", resource);
59+
curl_global_init(CURL_GLOBAL_ALL);
60+
std::string s;
61+
CURL* curl;
62+
CURLcode res;
63+
64+
curl = curl_easy_init();
65+
curl_easy_setopt(curl, CURLOPT_URL, "localhost:8080/base");
66+
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
67+
res = curl_easy_perform(curl);
68+
LT_ASSERT_EQ(res, 0);
69+
curl_easy_cleanup(curl);
70+
LT_END_AUTO_TEST(base)
71+
72+
LT_BEGIN_AUTO_TEST_ENV()
73+
AUTORUN_TESTS()
74+
LT_END_AUTO_TEST_ENV()

0 commit comments

Comments
 (0)