Ver código fonte

Test hio_new_ssl_ctx

ithewei 3 anos atrás
pai
commit
6faf68b180
2 arquivos alterados com 17 adições e 17 exclusões
  1. 5 5
      BUILD.md
  2. 12 12
      examples/tcp_echo_server.c

+ 5 - 5
BUILD.md

@@ -105,13 +105,13 @@ make clean && make
 ```
 
 ### compile WITH_OPENSSL
-Enable SSL in libhv is so easy, just only two apis:
+Enable SSL/TLS in libhv is so easy :)
 ```
-// init ssl_ctx, see ssl/hssl.h
-hssl_ctx_t hssl_ctx_init(hssl_ctx_init_param_t* param);
+// see ssl/hssl.h
+hssl_ctx_t hssl_ctx_new(hssl_ctx_opt_t* opt);
 
-// enable ssl, see event/hloop.h
-int hio_enable_ssl(hio_t* io);
+// see event/hloop.h
+int hio_new_ssl_ctx(hio_t* io, hssl_ctx_opt_t* opt);
 ```
 
 https is the best example.

+ 12 - 12
examples/tcp_echo_server.c

@@ -103,18 +103,6 @@ int main(int argc, char** argv) {
     }
 #endif
 
-#if TEST_SSL
-    hssl_ctx_init_param_t ssl_param;
-    memset(&ssl_param, 0, sizeof(ssl_param));
-    ssl_param.crt_file = "cert/server.crt";
-    ssl_param.key_file = "cert/server.key";
-    ssl_param.endpoint = HSSL_SERVER;
-    if (hssl_ctx_init(&ssl_param) == NULL) {
-        fprintf(stderr, "hssl_ctx_init failed!\n");
-        return -30;
-    }
-#endif
-
 #if TEST_UNPACK
     memset(&unpack_setting, 0, sizeof(unpack_setting_t));
     unpack_setting.package_max_length = DEFAULT_PACKAGE_MAX_LENGTH;
@@ -133,6 +121,18 @@ int main(int argc, char** argv) {
     if (listenio == NULL) {
         return -20;
     }
+#if TEST_SSL
+    hssl_ctx_opt_t ssl_param;
+    memset(&ssl_param, 0, sizeof(ssl_param));
+    ssl_param.crt_file = "cert/server.crt";
+    ssl_param.key_file = "cert/server.key";
+    ssl_param.endpoint = HSSL_SERVER;
+    if (hio_new_ssl_ctx(listenio, &ssl_param) != 0) {
+        fprintf(stderr, "hssl_ctx_new failed!\n");
+        return -30;
+    }
+#endif
+
     printf("listenfd=%d\n", hio_fd(listenio));
     hloop_run(loop);
     hloop_free(&loop);