X Tutup
Skip to content

Commit ea05368

Browse files
author
Sebastiano Merlino
committed
Solved some problems in server stopping
1 parent 7ba7e2a commit ea05368

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

src/webserver.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -956,21 +956,29 @@ bool webserver::is_running()
956956

957957
bool webserver::stop()
958958
{
959-
pthread_mutex_lock(&mutexwait);
960-
this->running = false;
961-
pthread_cond_signal(&mutexcond);
962-
pthread_mutex_unlock(&mutexwait);
963-
for(unsigned int i = 0; i < threads.size(); ++i)
959+
if(this->running)
964960
{
965-
int t_res;
966-
pthread_join(threads[i], (void**) &t_res);
961+
pthread_mutex_lock(&mutexwait);
962+
this->running = false;
963+
pthread_cond_signal(&mutexcond);
964+
pthread_mutex_unlock(&mutexwait);
965+
for(unsigned int i = 0; i < threads.size(); ++i)
966+
{
967+
void* t_res;
968+
pthread_join(threads[i], &t_res);
969+
free(t_res);
970+
}
971+
threads.clear();
972+
typedef vector<details::daemon_item*>::const_iterator daemon_item_it;
973+
for(daemon_item_it it = daemons.begin(); it != daemons.end(); ++it)
974+
delete *it;
975+
daemons.clear();
976+
return true;
977+
}
978+
else
979+
{
980+
return false;
967981
}
968-
threads.clear();
969-
typedef vector<details::daemon_item*>::const_iterator daemon_item_it;
970-
for(daemon_item_it it = daemons.begin(); it != daemons.end(); ++it)
971-
delete *it;
972-
daemons.clear();
973-
return true;
974982
}
975983

976984
void webserver::unregister_resource(const string& resource)

0 commit comments

Comments
 (0)
X Tutup