Przeglądaj źródła

Merge pull request #159 from hansipie/hansipie

check, refactor, isolation
bel2125 10 lat temu
rodzic
commit
ef29c71777
2 zmienionych plików z 10 dodań i 29 usunięć
  1. 6 29
      src/civetweb.c
  2. 4 0
      test/unit_test.c

+ 6 - 29
src/civetweb.c

@@ -1152,10 +1152,6 @@ typedef struct tagTHREADNAME_INFO {
 #include <sys/sendfile.h>
 #include <sys/sendfile.h>
 #endif
 #endif
 
 
-#if ((__GLIBC__ > 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 12)))
-#define GLIBC_CHK
-#endif
-
 static void mg_set_thread_name(const char *name)
 static void mg_set_thread_name(const char *name)
 {
 {
 	char threadName[16]; /* Max. thread length in Linux/OSX/.. */
 	char threadName[16]; /* Max. thread length in Linux/OSX/.. */
@@ -1188,33 +1184,14 @@ static void mg_set_thread_name(const char *name)
 	__except(EXCEPTION_EXECUTE_HANDLER) {}
 	__except(EXCEPTION_EXECUTE_HANDLER) {}
 #elif defined(__MINGW32__)
 #elif defined(__MINGW32__)
 	/* No option known to set thread name for MinGW */
 	/* No option known to set thread name for MinGW */
-	;
 #endif
 #endif
-#elif defined(__linux__)
-/* Linux */
-#if defined(GLIBC_CHK)
+#elif ((__GLIBC__ > 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 12)))
+	/* pthread_setname_np first appeared in glibc in version 2.12*/
 	(void)pthread_setname_np(pthread_self(), threadName);
 	(void)pthread_setname_np(pthread_self(), threadName);
-#else
+#elif defined(__linux__)
+	/* on linux we can use the old prctl function */
 	(void)prctl(PR_SET_NAME, threadName, 0, 0, 0);
 	(void)prctl(PR_SET_NAME, threadName, 0, 0, 0);
 #endif
 #endif
-#elif defined(__APPLE__) || defined(__MACH__)
-/* OS X */
-#if defined(GLIBC_CHK)
-	(void)pthread_setname_np(threadName);
-#endif
-#elif defined(BSD) || defined(__FreeBSD__) || defined(__OpenBSD__)
-/* BSD (TODO: test) */
-#if defined(GLIBC_CHK)
-	pthread_set_name_np(pthread_self(), threadName);
-#endif
-#elif defined(__AIX__) || defined(_AIX) || defined(__hpux) || defined(__sun)
-/* pthread_set_name_np seems to be missing on AIX, hpux, sun, ... */
-#else
-/* POSIX */
-#if defined(GLIBC_CHK)
-	(void)pthread_setname_np(pthread_self(), threadName);
-#endif
-#endif
 }
 }
 #else /* !defined(NO_THREAD_NAME) */
 #else /* !defined(NO_THREAD_NAME) */
 void mg_set_thread_name(const char *threadName) {}
 void mg_set_thread_name(const char *threadName) {}
@@ -8451,7 +8428,7 @@ static int parse_port_string(const struct vec *vec, struct socket *so)
 
 
 static int set_ports_option(struct mg_context *ctx)
 static int set_ports_option(struct mg_context *ctx)
 {
 {
-	const char *list = ctx->config[LISTENING_PORTS];
+	const char *list;
 	int on = 1;
 	int on = 1;
 #if defined(USE_IPV6)
 #if defined(USE_IPV6)
 	int off = 0;
 	int off = 0;
@@ -8473,7 +8450,7 @@ static int set_ports_option(struct mg_context *ctx)
 	memset(&so, 0, sizeof(so));
 	memset(&so, 0, sizeof(so));
 	memset(&usa, 0, sizeof(usa));
 	memset(&usa, 0, sizeof(usa));
 	len = sizeof(usa);
 	len = sizeof(usa);
-
+	list = ctx->config[LISTENING_PORTS];
 	while ((list = next_option(list, &vec, NULL)) != NULL) {
 	while ((list = next_option(list, &vec, NULL)) != NULL) {
 
 
 		portsTotal++;
 		portsTotal++;

+ 4 - 0
test/unit_test.c

@@ -432,15 +432,19 @@ static char *read_conn(struct mg_connection *conn, int *size)
 	return data;
 	return data;
 }
 }
 
 
+#ifdef MEMORY_DEBUGGING
 extern unsigned long mg_memory_debug_blockCount;
 extern unsigned long mg_memory_debug_blockCount;
 extern unsigned long mg_memory_debug_totalMemUsed;
 extern unsigned long mg_memory_debug_totalMemUsed;
+#endif
 
 
 static void ut_mg_stop(struct mg_context *ctx)
 static void ut_mg_stop(struct mg_context *ctx)
 {
 {
 	/* mg_stop for unit_test */
 	/* mg_stop for unit_test */
 	mg_stop(ctx);
 	mg_stop(ctx);
+#ifdef MEMORY_DEBUGGING
 	ASSERT(mg_memory_debug_blockCount == 0);
 	ASSERT(mg_memory_debug_blockCount == 0);
 	ASSERT(mg_memory_debug_totalMemUsed == 0);
 	ASSERT(mg_memory_debug_totalMemUsed == 0);
+#endif
 	mg_sleep(
 	mg_sleep(
 	    31000); /* This is required to ensure the operating system already
 	    31000); /* This is required to ensure the operating system already
 	               allows to use the port again */
 	               allows to use the port again */