@@ -66,26 +66,6 @@ using namespace std;
6666namespace 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-
8969using namespace http ;
9070
9171int 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