Skip to content

Commit 0ee9233

Browse files
author
Sebastiano Merlino
committed
Added capability to compile with gcov
Changed infinite loop in ws to use wait conditions Removed a bug from GET-like method handling
1 parent cea0fe9 commit 0ee9233

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

Makefile.am

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ SUBDIRS = src $(PYTHON_DIR) $(JAVA_DIR) $(PHP_DIR) $(LUA_DIR) $(PERL_DIR) $(RUBY
2828
DIST_SUBDIRS = src $(PYTHON_DIST_DIR) $(JAVA_DIST_DIR) $(PHP_DIST_DIR) $(LUA_DIST_DIR) $(PERL_DIST_DIR) $(RUBY_DIST_DIR) $(GUILE_DIST_DIR)
2929
EXTRA_DIST = libhttpserver.pc.in debian/changelog.in debian/control.in debian/rules.in debian/libhttpserver-dev.install.in debian/libhttpserver.install.in redhat/libhttpserver.SPEC.in $(DX_CONFIG) $(PYTHON_EXTRA) $(PHP_EXTRA) $(PERL_EXTRA)
3030

31-
MOSTLYCLEANFILES = $(DX_CLEANFILES) redhat/SOURCES/* $(top_srcdir)/src/java/*.java $(top_srcdir)/src/java/webserver_wrap.*
31+
JAVACLEANFILES = $(top_srcdir)/src/java/*.java $(top_srcdir)/src/java/webserver_wrap.*
32+
PYTHONCLEANFILES = $(top_srcdir)/src/python/*.py $(top_srcdir)/src/python/webserver_wrap.*
33+
34+
MOSTLYCLEANFILES = $(DX_CLEANFILES) redhat/SOURCES/* $(JAVACLEANFILES) $(PYTHONCLEANFILES)
3235
DISTCLEANFILES = redhat/SOURCES/* redhat/SPEC/* redhat/* debian/* DIST_REVISION
3336

3437
pkgconfigdir = $(libdir)/pkgconfig

configure.ac

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ AC_MSG_RESULT([$debugit])
148148

149149
if test x"$debugit" = x"yes"; then
150150
AC_DEFINE([DEBUG],[],[Debug Mode])
151-
AM_CXXFLAGS="$AM_CXXFLAGS -DDEBUG -g -Wall -Wno-uninitialized -O0"
151+
AM_CXXFLAGS="$AM_CXXFLAGS -DDEBUG -g -Wall -Wno-uninitialized -O0 -fprofile-arcs -ftest-coverage"
152+
LDFLAGS="-lgcov $LDFLAGS"
152153
else
153154
AC_DEFINE([NDEBUG],[],[No-debug Mode])
154155
AM_CXXFLAGS="$AM_CXXFLAGS -O3"

src/httpserver/webserver.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
#include <utility>
4545
#include <memory>
4646

47+
#include <pthread.h>
48+
4749
namespace httpserver {
4850

4951
class http_resource;
@@ -260,6 +262,8 @@ class webserver
260262
bool ban_system_enabled;
261263
bool post_process_enabled;
262264
bool single_resource;
265+
pthread_mutex_t mutexwait;
266+
pthread_cond_t mutexcond;
263267

264268
std::map<http_endpoint, http_resource* > registered_resources;
265269
#ifdef USE_CPP_ZEROX

src/webserver.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ webserver::webserver
223223
else
224224
this->single_resource = false;
225225
ignore_sigpipe();
226+
pthread_mutex_init(&mutexwait, NULL);
227+
pthread_cond_init(&mutexcond, NULL);
226228
}
227229

228230
webserver::webserver(const create_webserver& params):
@@ -266,16 +268,20 @@ webserver::webserver(const create_webserver& params):
266268
else
267269
this->single_resource = false;
268270
ignore_sigpipe();
271+
pthread_mutex_init(&mutexwait, NULL);
272+
pthread_cond_init(&mutexcond, NULL);
269273
}
270274

271275
webserver::~webserver()
272276
{
273277
this->stop();
278+
pthread_mutex_destroy(&mutexwait);
279+
pthread_cond_destroy(&mutexcond);
274280
}
275281

276282
void webserver::sweet_kill()
277283
{
278-
this->running = false;
284+
this->stop();
279285
}
280286

281287
void webserver::request_completed (void *cls, struct MHD_Connection *connection, void **con_cls, enum MHD_RequestTerminationCode toe)
@@ -380,15 +386,17 @@ bool webserver::start(bool blocking)
380386
Py_BEGIN_ALLOW_THREADS;
381387
}
382388
#endif
389+
pthread_mutex_lock(&mutexwait);
383390
while(blocking && running)
384-
sleep(1);
391+
pthread_cond_wait(&mutexcond, &mutexwait);
392+
pthread_mutex_unlock(&mutexwait);
385393
#ifdef WITH_PYTHON
386394
if(PyEval_ThreadsInitialized())
387395
{
388396
Py_END_ALLOW_THREADS;
389397
}
390398
#endif
391-
value_onclose = this->stop();
399+
value_onclose = true;
392400
}
393401
return value_onclose;
394402
}
@@ -400,11 +408,14 @@ bool webserver::is_running()
400408

401409
bool webserver::stop()
402410
{
411+
pthread_mutex_lock(&mutexwait);
403412
if(this->running)
404413
{
405414
MHD_stop_daemon (this->daemon);
406415
this->running = false;
407416
}
417+
pthread_cond_signal(&mutexcond);
418+
pthread_mutex_unlock(&mutexwait);
408419
return true;
409420
}
410421

@@ -665,7 +676,7 @@ int webserver::answer_to_connection(void* cls, MHD_Connection* connection,
665676
mr->dhr->set_path(st_url);
666677
mr->dhr->set_method(method);
667678

668-
/* if ( 0 == strcmp(method, MHD_HTTP_METHOD_DELETE) ||
679+
/* if (0 == strcmp(method, MHD_HTTP_METHOD_DELETE) ||
669680
0 == strcmp(method, MHD_HTTP_METHOD_GET) ||
670681
0 == strcmp(method, MHD_HTTP_METHOD_CONNECT) ||
671682
0 == strcmp(method, MHD_HTTP_METHOD_HEAD) ||
@@ -692,7 +703,12 @@ int webserver::answer_to_connection(void* cls, MHD_Connection* connection,
692703
return MHD_YES;
693704
}
694705
}
695-
else
706+
else if(0 != strcmp(method, MHD_HTTP_METHOD_DELETE) &&
707+
0 != strcmp(method, MHD_HTTP_METHOD_GET) &&
708+
0 != strcmp(method, MHD_HTTP_METHOD_CONNECT) &&
709+
0 != strcmp(method, MHD_HTTP_METHOD_HEAD) &&
710+
0 != strcmp(method, MHD_HTTP_METHOD_TRACE)
711+
)
696712
{
697713
return method_not_acceptable_page(cls, connection);
698714
}

0 commit comments

Comments
 (0)