浏览代码

Added mg_is_context_stopped

Long running client code sometimes needs to know when civetweb is
exiting so that it can cleanly abort a long process.
Joe Mucchiello 10 年之前
父节点
当前提交
a2b208bdbf
共有 2 个文件被更改,包括 16 次插入0 次删除
  1. 10 0
      include/civetweb.h
  2. 6 0
      src/civetweb.c

+ 10 - 0
include/civetweb.h

@@ -743,6 +743,16 @@ CIVETWEB_API int mg_get_response(struct mg_connection *conn,
 CIVETWEB_API unsigned mg_check_feature(unsigned feature);
 
 
+/* Get the stopping status of a given civetweb context.
+
+   Return:
+    0: context is running normally
+	1: context is shutting down
+	2: context has stopped
+   -1: Invalid context
+ */
+CIVETWEB_API int mg_is_ctx_stopped(const struct mg_context* ctx)
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */

+ 6 - 0
src/civetweb.c

@@ -10754,6 +10754,12 @@ struct mg_context *mg_start(const struct mg_callbacks *callbacks,
 	return ctx;
 }
 
+int mg_is_ctx_stopped(const struct mg_context* ctx)
+{
+	if (!ctx) return -1;
+
+	return ctx->stop_flag;
+}
 
 /* Feature check API function */
 unsigned mg_check_feature(unsigned feature)