浏览代码

allow CivetServer constructor to accept options as std::vector<std::string>
https://github.com/civetweb/civetweb/issues/233

brett 9 年之前
父节点
当前提交
c07b562d2d
共有 2 个文件被更改,包括 27 次插入0 次删除
  1. 1 0
      include/CivetServer.h
  2. 26 0
      src/CivetServer.cpp

+ 1 - 0
include/CivetServer.h

@@ -170,6 +170,7 @@ class CIVETWEB_API CivetServer
 	 * @throws CivetException
 	 */
 	CivetServer(const char **options, const struct mg_callbacks *callbacks = 0);
+	CivetServer(std::vector<std::string> options, const struct mg_callbacks *callbacks = 0);
 
 	/**
 	 * Destructor

+ 26 - 0
src/CivetServer.cpp

@@ -237,6 +237,32 @@ CivetServer::CivetServer(const char **options,
 		throw CivetException("null context when constructing CivetServer. "
 		                     "Possible problem binding to port.");
 }
+CivetServer::CivetServer(std::vector<std::string> options,
+                         const struct mg_callbacks *_callbacks)
+    : context(0)
+{
+	struct mg_callbacks callbacks;
+	memset(&callbacks, 0, sizeof(callbacks));
+
+	if (_callbacks) {
+		callbacks = *_callbacks;
+		userCloseHandler = _callbacks->connection_close;
+	} else {
+		userCloseHandler = NULL;
+	}
+	callbacks.connection_close = closeHandler;
+
+	std::vector<const char*> pointers(options.size());
+	for (int i=0; i<options.size(); i++) {
+		pointers.push_back( options[i].c_str() );
+	}
+	pointers.push_back(0);
+
+	context = mg_start(&callbacks, this, &pointers[0]);
+	if (context == NULL)
+		throw CivetException("null context when constructing CivetServer. "
+		                     "Possible problem binding to port.");
+}
 
 CivetServer::~CivetServer()
 {