hewei.it 5 tahun lalu
induk
melakukan
de6f39e9ba
14 mengubah file dengan 2114 tambahan dan 49 penghapusan
  1. 3 0
      .gitignore
  2. 1 0
      BUILD.md
  3. 1 0
      CMake/vars.cmake
  4. 19 9
      CMakeLists.txt
  5. 1 0
      Makefile.vars
  6. 1 0
      README.md
  7. 0 4
      base/ifconfig.cpp
  8. 5 0
      base/ifconfig.h
  9. 0 0
      getting_started.sh
  10. 1 1
      http/client/http_client.cpp
  11. 2 1
      http/http_content.h
  12. 2 4
      utils/hmain.cpp
  13. 4 0
      utils/hmain.h
  14. 2074 30
      utils/json.hpp

+ 3 - 0
.gitignore

@@ -58,3 +58,6 @@ build
 *.vcxproj.*
 Debug
 Release
+
+# other
+hconfig.h

+ 1 - 0
BUILD.md

@@ -40,6 +40,7 @@ mkdir build
 cd build
 cmake ..
 make libhv
+make libhv_static
 make unittest
 make examples
 ```

+ 1 - 0
CMake/vars.cmake

@@ -59,6 +59,7 @@ set(HTTP_HEADERS
     http/grpcdef.h
     http/http_content.h
     http/HttpMessage.h
+    http/HttpParser.h
 )
 
 set(HTTP_CLIENT_HEADERS http/client/http_client.h)

+ 19 - 9
CMakeLists.txt

@@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.0)
 
 project(hv VERSION 1.20)
 
-# TARGET_TYPE = SHARED or STATIC
-set(TARGET_TYPE SHARED)
+option(BUILD_SHARED "build shared library" ON)
+option(BUILD_STATIC "build static library" ON)
 
 # see config.mk
 option(WITH_PROTOCOL "compile protocol" ON)
@@ -148,15 +148,25 @@ if(WITH_HTTP)
 endif()
 
 list_source_directories(LIBHV_SRCS ${LIBHV_SRCDIRS})
-add_library(hv ${TARGET_TYPE} ${LIBHV_SRCS})
-target_include_directories(hv PRIVATE ${LIBHV_SRCDIRS})
-target_link_libraries(hv ${LIBS})
+
+if(BUILD_SHARED)
+    add_library(hv SHARED ${LIBHV_SRCS})
+    target_compile_definitions(hv PRIVATE HV_EXPORTS)
+    target_include_directories(hv PRIVATE ${LIBHV_SRCDIRS})
+    target_link_libraries(hv ${LIBS})
+    install(TARGETS hv)
+    add_custom_target(libhv DEPENDS hv)
+endif()
+
+if(BUILD_STATIC)
+    add_library(hv_static STATIC ${LIBHV_SRCS})
+    target_compile_definitions(hv_static PRIVATE HV_STATICLIB)
+    target_include_directories(hv_static PRIVATE ${LIBHV_SRCDIRS})
+    install(TARGETS hv_static)
+    add_custom_target(libhv_static DEPENDS hv_static)
+endif()
 
 install(FILES ${LIBHV_HEADERS} DESTINATION include/hv)
-install(TARGETS hv)
 
 add_subdirectory(unittest)
 add_subdirectory(examples)
-
-add_custom_target(libhv   DEPENDS hv)
-add_custom_target(default DEPENDS hv)

+ 1 - 0
Makefile.vars

@@ -57,6 +57,7 @@ HTTP_HEADERS =  http/httpdef.h\
 				http/grpcdef.h\
 				http/http_content.h\
 				http/HttpMessage.h\
+				http/HttpParser.h\
 
 HTTP_CLIENT_HEADERS = http/client/http_client.h
 

+ 1 - 0
README.md

@@ -80,6 +80,7 @@ int main(int argc, char* argv[]) {
 ```
 
 ```shell
+# see getting_started.sh
 git clone https://github.com/ithewei/libhv.git
 cd libhv
 make httpd curl

+ 0 - 4
base/ifconfig.cpp

@@ -97,10 +97,6 @@ int ifconfig(std::vector<ifconfig_t>& ifcs) {
 #include <windows.h>
 #include <ws2ipdef.h>
 #include <iphlpapi.h>
-#ifdef _MSC_VER
-#pragma comment(lib, "iphlpapi.lib")
-#pragma comment(lib, "ws2_32.lib")
-#endif
 int ifconfig(std::vector<ifconfig_t>& ifcs) {
     PIP_ADAPTER_ADDRESSES pAddrs = NULL;
     ULONG buflen = 0;

+ 5 - 0
base/ifconfig.h

@@ -3,6 +3,11 @@
 
 #include <vector>
 
+#ifdef _MSC_VER
+#pragma comment(lib, "iphlpapi.lib")
+#pragma comment(lib, "ws2_32.lib")
+#endif
+
 typedef struct ifconfig_s {
     char name[128];
     char ip[16];

+ 0 - 0
html/downloads/scripts/getting_started.sh → getting_started.sh


+ 1 - 1
http/client/http_client.cpp

@@ -314,7 +314,7 @@ static int __http_client_connect(http_client_t* cli) {
     }
     int connfd = ConnectTimeout(cli->host.c_str(), cli->port, blocktime);
     if (connfd < 0) {
-        return socket_errno();
+        return connfd;
     }
     tcp_nodelay(connfd, 1);
 

+ 2 - 1
http/http_content.h

@@ -43,7 +43,7 @@ struct FormData {
     }
 };
 
-// Multipart
+// MultiPart
 // name => FormData
 typedef HV_MAP<std::string, FormData>          MultiPart;
 #define DEFAULT_MULTIPART_BOUNDARY  "----WebKitFormBoundary7MA4YWxkTrZu0gW"
@@ -51,6 +51,7 @@ std::string dump_multipart(MultiPart& mp, const char* boundary = DEFAULT_MULTIPA
 int         parse_multipart(std::string& str, MultiPart& mp, const char* boundary);
 
 // Json
+// https://github.com/nlohmann/json
 #include "json.hpp"
 using Json = nlohmann::json;
 extern std::string g_parse_json_errmsg;

+ 2 - 4
utils/hmain.cpp

@@ -392,14 +392,12 @@ int signal_init(procedure_t reload_fn, void* reload_userdata) {
 }
 
 #elif defined(OS_WIN)
+#include <mmsystem.h> // for timeSetEvent
+
 // win32 use Event
 //static HANDLE s_hEventTerm = NULL;
 static HANDLE s_hEventReload = NULL;
 
-#include <mmsystem.h>
-#ifdef _MSC_VER
-#pragma comment(lib, "winmm.lib")
-#endif
 void WINAPI on_timer(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2) {
     DWORD ret;
     /*

+ 4 - 0
utils/hmain.h

@@ -6,6 +6,10 @@
 #include "hstring.h"
 #include "hproc.h"
 
+#ifdef _MSC_VER
+#pragma comment(lib, "winmm.lib") // for timeSetEvent
+#endif
+
 typedef struct main_ctx_s {
     char    run_dir[MAX_PATH];
     char    program_name[MAX_PATH];

File diff ditekan karena terlalu besar
+ 2074 - 30
utils/json.hpp


Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini