Skip to content

Commit 27a430f

Browse files
committed
Removing daemon_item. Simplifying the logic
1 parent 070976f commit 27a430f

File tree

2 files changed

+6
-32
lines changed

2 files changed

+6
-32
lines changed

src/httpserver/webserver.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ struct httpserver_ska;
5959
};
6060

6161
namespace details {
62-
struct daemon_item;
6362
struct modded_request;
6463
}
6564

@@ -188,7 +187,7 @@ class webserver
188187
std::set<http::ip_representation> bans;
189188
std::set<http::ip_representation> allowances;
190189

191-
std::vector<details::daemon_item*> daemons;
190+
struct MHD_Daemon* daemon;
192191

193192
static void* select(void* self);
194193
static void* cleaner(void* self);

src/webserver.cpp

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,6 @@ using namespace std;
6666
namespace httpserver
6767
{
6868

69-
namespace details
70-
{
71-
72-
struct daemon_item
73-
{
74-
webserver* ws;
75-
struct MHD_Daemon* daemon;
76-
daemon_item(webserver* ws, struct MHD_Daemon* daemon):
77-
ws(ws),
78-
daemon(daemon)
79-
{
80-
}
81-
~daemon_item()
82-
{
83-
MHD_stop_daemon (this->daemon);
84-
}
85-
};
86-
87-
}
88-
8969
using namespace http;
9070

9171
int policy_callback (void *, const struct sockaddr*, socklen_t);
@@ -329,29 +309,27 @@ bool webserver::start(bool blocking)
329309
start_conf |= MHD_USE_TCP_FASTOPEN;
330310
#endif
331311

332-
struct MHD_Daemon* daemon = NULL;
312+
this->daemon = NULL;
333313
if(bind_address == 0x0) {
334-
daemon = MHD_start_daemon
314+
this->daemon = MHD_start_daemon
335315
(
336316
start_conf, this->port, &policy_callback, this,
337317
&answer_to_connection, this, MHD_OPTION_ARRAY,
338318
&iov[0], MHD_OPTION_END
339319
);
340320
} else {
341-
daemon = MHD_start_daemon
321+
this->daemon = MHD_start_daemon
342322
(
343323
start_conf, 1, &policy_callback, this,
344324
&answer_to_connection, this, MHD_OPTION_ARRAY,
345325
&iov[0], MHD_OPTION_SOCK_ADDR, bind_address, MHD_OPTION_END
346326
);
347327
}
348328

349-
if(NULL == daemon)
329+
if(this->daemon == NULL)
350330
{
351331
throw std::invalid_argument("Unable to connect daemon to port: " + this->port);
352332
}
353-
details::daemon_item* di = new details::daemon_item(this, daemon);
354-
daemons.push_back(di);
355333

356334
bool value_onclose = false;
357335

@@ -381,11 +359,8 @@ bool webserver::stop()
381359
this->running = false;
382360
pthread_cond_signal(&mutexcond);
383361
pthread_mutex_unlock(&mutexwait);
384-
typedef vector<details::daemon_item*>::const_iterator daemon_item_it;
385362

386-
for(daemon_item_it it = daemons.begin(); it != daemons.end(); ++it)
387-
delete *it;
388-
daemons.clear();
363+
MHD_stop_daemon(this->daemon);
389364

390365
shutdown(bind_socket, 2);
391366

0 commit comments

Comments
 (0)