hewei.it пре 4 година
родитељ
комит
6c02cf272c

+ 14 - 1
examples/http_server_test.cpp

@@ -5,6 +5,7 @@
  */
 
 #include "HttpServer.h"
+#include "hssl.h"
 
 int main() {
     HV_MEMCHECK;
@@ -30,12 +31,24 @@ int main() {
     });
 
     http_server_t server;
+    server.service = &router;
     server.port = 8080;
+#if 0
+    server.https_port = 8443;
+    hssl_ctx_init_param_t param;
+    memset(&param, 0, sizeof(param));
+    param.crt_file = "cert/server.crt";
+    param.key_file = "cert/server.key";
+    if (hssl_ctx_init(&param) == NULL) {
+        fprintf(stderr, "SSL certificate verify failed!\n");
+        return -20;
+    }
+#endif
+
     // uncomment to test multi-processes
     // server.worker_processes = 4;
     // uncomment to test multi-threads
     // server.worker_threads = 4;
-    server.service = &router;
 
 #if 1
     http_server_run(&server);

+ 4 - 2
examples/httpd/httpd.cpp

@@ -114,7 +114,9 @@ int parse_confile(const char* confile) {
     }
     g_http_server.port = port;
     // https_port
-    g_http_server.https_port = ini.Get<int>("https_port");
+    if (HV_WITH_SSL) {
+        g_http_server.https_port = ini.Get<int>("https_port");
+    }
     if (g_http_server.port == 0 && g_http_server.https_port == 0) {
         printf("Please config listen port!\n");
         exit(-10);
@@ -146,7 +148,7 @@ int parse_confile(const char* confile) {
         g_http_service.index_of = str;
     }
     // ssl
-    if (g_http_server.https_port > 0 && HV_WITH_SSL) {
+    if (g_http_server.https_port > 0) {
         std::string crt_file = ini.GetValue("ssl_certificate");
         std::string key_file = ini.GetValue("ssl_privatekey");
         std::string ca_file = ini.GetValue("ssl_ca_certificate");

+ 3 - 2
examples/websocket_server_test.cpp

@@ -45,9 +45,10 @@ int main(int argc, char** argv) {
     };
 
     websocket_server_t server;
+#if 1
     server.port = port;
-#if 0
-    server.ssl = 1;
+#else
+    server.https_port = port;
     hssl_ctx_init_param_t param;
     memset(&param, 0, sizeof(param));
     param.crt_file = "cert/server.crt";

+ 2 - 0
http/server/HttpServer.cpp

@@ -352,11 +352,13 @@ int http_server_run(http_server_t* server, int wait) {
     if (server->port > 0) {
         server->listenfd[0] = Listen(server->port, server->host);
         if (server->listenfd[0] < 0) return server->listenfd[0];
+        hlogi("http server listening on %s:%d", server->host, server->port);
     }
     // https_port
     if (server->https_port > 0 && hssl_ctx_instance() != NULL) {
         server->listenfd[1] = Listen(server->https_port, server->host);
         if (server->listenfd[1] < 0) return server->listenfd[1];
+        hlogi("https server listening on %s:%d", server->host, server->https_port);
     }
     // service
     if (server->service == NULL) {