Author: rhuijben
Date: Tue Nov 17 22:53:07 2015
New Revision: 1714902
URL: http://svn.apache.org/viewvc?rev=1714902&view=rev
Log:
Handle some signals like we do in Subversion to allow going through the
proper cleanup handling when exiting. This will help in tracking memory
leaks.
* test/serf_httpd.c
(includes): Add apr_signal.h.
(cancelled): Add variable.
(signal_handler): New function.
(main): Register signals. Check for cancelled.
Modified:
serf/trunk/test/serf_httpd.c
Modified: serf/trunk/test/serf_httpd.c
URL:
http://svn.apache.org/viewvc/serf/trunk/test/serf_httpd.c?rev=1714902&r1=1714901&r2=1714902&view=diff
==============================================================================
--- serf/trunk/test/serf_httpd.c (original)
+++ serf/trunk/test/serf_httpd.c Tue Nov 17 22:53:07 2015
@@ -22,6 +22,7 @@
#include <apr.h>
#include <apr_uri.h>
+#include <apr_signal.h>
#include <apr_strings.h>
#include <apr_atomic.h>
#include <apr_base64.h>
@@ -63,6 +64,18 @@ static int pool_abort_func(int retcode)
return 0;
}
+/* A flag to see if we've been cancelled by the client or not. */
+static volatile sig_atomic_t cancelled = FALSE;
+
+/* A signal handler to support cancellation. */
+static void
+signal_handler(int signum)
+{
+ apr_signal(signum, SIG_IGN);
+ cancelled = TRUE;
+}
+
+
static apr_status_t client_setup(apr_socket_t *skt,
serf_bucket_t **read_bkt,
serf_bucket_t **write_bkt,
@@ -383,6 +396,24 @@ int main(int argc, const char **argv)
apr_allocator_max_free_set(allocator, 16384 * 1024);
/* else: APR pool debugging... leave this to apr */
+ apr_signal(SIGINT, signal_handler);
+#ifdef SIGBREAK
+ /* SIGBREAK is a Win32 specific signal generated by ctrl-break. */
+ apr_signal(SIGBREAK, signal_handler);
+#endif
+#ifdef SIGHUP
+ apr_signal(SIGHUP, signal_handler);
+#endif
+#ifdef SIGTERM
+ apr_signal(SIGTERM, signal_handler);
+#endif
+
+#ifdef SIGPIPE
+ /* Disable SIGPIPE generation for the platforms that have it. */
+ apr_signal(SIGPIPE, SIG_IGN);
+#endif
+
+
apr_pool_create(&scratch_pool, app_pool);
apr_getopt_init(&opt, scratch_pool, argc, argv);
@@ -416,9 +447,14 @@ int main(int argc, const char **argv)
while (1) {
apr_pool_clear(scratch_pool);
- status = serf_context_run(context, SERF_DURATION_FOREVER,
scratch_pool);
- if (APR_STATUS_IS_TIMEUP(status))
- continue;
+ status = serf_context_run(context, apr_time_from_msec(50),
+ scratch_pool);
+ if (APR_STATUS_IS_TIMEUP(status)) {
+ if (cancelled)
+ break;
+ else
+ continue;
+ }
if (status) {
char buf[200];
const char *err_string;