adamdebreceni commented on a change in pull request #818:
URL: https://github.com/apache/nifi-minifi-cpp/pull/818#discussion_r444673905
##########
File path: extensions/http-curl/tests/TestServer.h
##########
@@ -24,65 +24,87 @@
#include "CivetServer.h"
#include "civetweb.h"
#include "HTTPUtils.h"
+#include "ServerAwareHandler.h"
-
-/* Server context handle */
-static std::string resp_str;
-
-void init_webserver() {
- mg_init_library(0);
-}
-
-
-CivetServer * start_webserver(std::string &port, std::string &rooturi,
CivetHandler *handler, struct mg_callbacks *callbacks, std::string &cert,
std::string &ca_cert) {
- const char *options[] = { "document_root", ".", "listening_ports",
port.c_str(), "error_log_file",
- "error.log", "ssl_certificate", ca_cert.c_str(), "ssl_protocol_version",
"4", "ssl_cipher_list",
- "ALL", "request_timeout_ms", "10000", "enable_auth_domain_check", "no",
"ssl_verify_peer", "no", 0 };
-// ECDH+AESGCM+AES256:!aNULL:!MD5:!DSS
- std::vector<std::string> cpp_options;
- for (size_t i = 0; i < (sizeof(options) / sizeof(options[0]) - 1); i++) {
- cpp_options.push_back(options[i]);
- }
-
- if (!mg_check_feature(2)) {
- fprintf(stderr,
- "Error: Embedded example built with SSL support, "
- "but civetweb library build without.\n");
- return 0;
+/**
+ * A wrapper around CivetServer which notifies Handlers before shutdown,
+ * so they wouldn't get stuck (if a handler returns after shutdown is
+ * initiated it might get stuck inside worker_thread_run > consume_socket)
+ */
+class TestServer{
+ struct CivetLibrary{
+ CivetLibrary() {
+ if (getCounter()++ == 0) {
+ mg_init_library(0);
+ }
+ }
+ ~CivetLibrary() {
+ if (--getCounter() == 0) {
Review comment:
will make the `getCounter` static, we do not access a member though this
getter, but a static library initialization counter
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]