hewei.it 4 роки тому
батько
коміт
2ba2969064

+ 16 - 1
examples/http_server_test.cpp

@@ -7,6 +7,21 @@
 #include "HttpServer.h"
 #include "hssl.h"
 
+/*
+ * #define TEST_HTTPS 1
+ *
+ * @build   ./configure --with-openssl && make clean && make
+ *
+ * @server  bin/http_server_test
+ *
+ * @client  curl -v http://127.0.0.1:8080/ping
+ *          curl -v https://127.0.0.1:8443/ping --insecure
+ *          bin/curl -v http://127.0.0.1:8080/ping
+ *          bin/curl -v https://127.0.0.1:8443/ping
+ *
+ */
+#define TEST_HTTPS 0
+
 int main() {
     HV_MEMCHECK;
 
@@ -33,7 +48,7 @@ int main() {
     http_server_t server;
     server.service = &router;
     server.port = 8080;
-#if 0
+#if TEST_HTTPS
     server.https_port = 8443;
     hssl_ctx_init_param_t param;
     memset(&param, 0, sizeof(param));

+ 15 - 0
examples/nc.c

@@ -15,6 +15,16 @@
 #include "hloop.h"
 #include "hbase.h"
 #include "hsocket.h"
+#include "hssl.h"
+
+/*
+ * @test    ssl_client
+ * #define  TEST_SSL 1
+ *
+ * @build   ./configure --with-openssl && make clean && make
+ *
+ */
+#define TEST_SSL 0
 
 #define RECV_BUFSIZE    8192
 static char recvbuf[RECV_BUFSIZE];
@@ -168,8 +178,13 @@ Examples: nc 127.0.0.1 80\n\
 
     // socket
     if (protocol == 1) {
+#if TEST_SSL
+        // ssl
+        sockio = hloop_create_ssl_client(loop, host, port, on_connect);
+#else
         // tcp
         sockio = hloop_create_tcp_client(loop, host, port, on_connect);
+#endif
     }
     else if (protocol == 2) {
         // udp

+ 27 - 0
examples/tcp_echo_server.c

@@ -10,6 +10,16 @@
 
 #include "hloop.h"
 #include "hsocket.h"
+#include "hssl.h"
+
+/*
+ * @test    ssl_server
+ * #define  TEST_SSL 1
+ *
+ * @build   ./configure --with-openssl && make clean && make
+ *
+ */
+#define TEST_SSL 0
 
 // hloop_create_tcp_server -> on_accept -> hio_read -> on_recv -> hio_write
 
@@ -50,8 +60,25 @@ int main(int argc, char** argv) {
     }
     int port = atoi(argv[1]);
 
+#if TEST_SSL
+    {
+        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 -30;
+        }
+    }
+#endif
+
     hloop_t* loop = hloop_new(0);
+#if TEST_SSL
+    hio_t* listenio = hloop_create_ssl_server(loop, "0.0.0.0", port, on_accept);
+#else
     hio_t* listenio = hloop_create_tcp_server(loop, "0.0.0.0", port, on_accept);
+#endif
     if (listenio == NULL) {
         return -20;
     }

+ 15 - 3
examples/websocket_server_test.cpp

@@ -13,6 +13,19 @@
 #include "htime.h"
 #include "hssl.h"
 
+/*
+ * #define TEST_WSS 1
+ *
+ * @build   ./configure --with-openssl && make clean && make
+ *
+ * @server  bin/websocket_server_test 9999
+ *
+ * @client  bin/websocket_client_test ws://127.0.0.1:9999/
+ *          bin/websocket_client_test wss://127.0.0.1:10000/
+ *
+ */
+#define TEST_WSS 0
+
 using namespace hv;
 
 int main(int argc, char** argv) {
@@ -45,10 +58,9 @@ int main(int argc, char** argv) {
     };
 
     websocket_server_t server;
-#if 1
     server.port = port;
-#else
-    server.https_port = port;
+#if TEST_WSS
+    server.https_port = port + 1;
     hssl_ctx_init_param_t param;
     memset(&param, 0, sizeof(param));
     param.crt_file = "cert/server.crt";