瀏覽代碼

Add a define SSL_ALREADY_INITIALIZED

This define should be set if civetweb is embeded into a host application
that did already set up SSL (libcrypto).
See also comment "cryptolib_users = 1", issue #58
bel2125 10 年之前
父節點
當前提交
b6088ee7eb
共有 3 個文件被更改,包括 10 次插入1 次删除
  1. 1 0
      docs/Building.md
  2. 4 0
      docs/Embedding.md
  3. 5 1
      src/civetweb.c

+ 1 - 0
docs/Building.md

@@ -98,6 +98,7 @@ make build COPT="-DNDEBUG -DNO_CGI"
 | NO_SSL_DL                 | link against system libssl library   |
 | NO_FILES                  | do not serve files from a directory  |
 | SQLITE_DISABLE_LFS        | disables large files (Lua only)      |
+| SSL_ALREADY_INITIALIZED   | do not initialize libcrypto          |
 
 ## Cross Compiling
 

+ 4 - 0
docs/Embedding.md

@@ -125,6 +125,10 @@ two threads: a master thread, that accepts new connections, and several
 worker threads, that process accepted connections. The number of worker threads
 is configurable via `num_threads` configuration option. That number puts a
 limit on number of simultaneous requests that can be handled by civetweb.
+If you embed civetweb into a program that uses SSL outside civetweb as well,
+you may need to initialize SSL before calling `mg_start()`, and set the pre-
+processor define SSL_ALREADY_INITIALIZED. This is not required if SSL is used
+only within civetweb.
 
 When master thread accepts new connection, a new accepted socket (described by
 `struct socket`) it placed into the accepted sockets queue,

+ 5 - 1
src/civetweb.c

@@ -6721,7 +6721,11 @@ static void *cryptolib_dll_handle;     /* Store the crypto library handle. */
 
 #endif /* NO_SSL_DL */
 
-static int cryptolib_users = 0;        /* Refecence counter for crypto library. */
+#if defined(SSL_ALREADY_INITIALIZED)
+static int cryptolib_users = 1;        /* Reference counter for crypto library. */
+#else
+static int cryptolib_users = 0;        /* Reference counter for crypto library. */
+#endif
 
 static int initialize_ssl(struct mg_context *ctx)
 {