Browse Source

add windows dll versions resource (#712)

add cmake install windows debug pdb
fix known compilation warnings
宅の士 8 months ago
parent
commit
1e3dd552fd
9 changed files with 73 additions and 8 deletions
  1. 9 0
      CMakeLists.txt
  2. 2 2
      base/hatomic.h
  3. 1 1
      base/hbase.c
  4. 3 1
      base/rbtree.h
  5. 1 0
      evpp/EventLoop.h
  6. 1 0
      evpp/TcpClient.h
  7. 10 0
      http/server/HttpServer.cpp
  8. 11 4
      http/websocket_parser.c
  9. 35 0
      hv.rc.in

+ 9 - 0
CMakeLists.txt

@@ -238,6 +238,11 @@ if(WITH_MQTT)
 endif()
 
 list_source_directories(LIBHV_SRCS ${LIBHV_SRCDIRS})
+if(WIN32)
+    set(CMAKE_RC_FLAGS_DEBUG -D_DEBUG)
+    configure_file(${PROJECT_SOURCE_DIR}/${PROJECT_NAME}.rc.in ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.rc)
+    list(APPEND LIBHV_SRCS ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.rc)
+endif()
 
 file(INSTALL ${LIBHV_HEADERS} DESTINATION include/hv)
 file(INSTALL ${LIBHV_HEADERS} DESTINATION ${PROJECT_SOURCE_DIR}/include/hv)
@@ -268,6 +273,10 @@ if(BUILD_STATIC)
     add_custom_target(libhv_static DEPENDS hv_static)
 endif()
 
+if(WIN32)
+    install(FILES $<TARGET_PDB_FILE:${PROJECT_NAME}> DESTINATION bin OPTIONAL)
+endif()
+
 install(FILES ${LIBHV_HEADERS} DESTINATION include/hv)
 install(EXPORT libhvConfig DESTINATION lib/cmake/libhv)
 

+ 2 - 2
base/hatomic.h

@@ -42,14 +42,14 @@ typedef volatile long long          atomic_llong;
 typedef volatile unsigned long long atomic_ullong;
 typedef volatile size_t             atomic_size_t;
 
-typedef struct atomic_flag { atomic_bool _Value; } atomic_flag;
+typedef struct atomic_flag { atomic_long _Value; } atomic_flag;
 
 #ifdef _WIN32
 
 #define ATOMIC_FLAG_TEST_AND_SET    atomic_flag_test_and_set
 static inline bool atomic_flag_test_and_set(atomic_flag* p) {
     // return InterlockedIncrement((LONG*)&p->_Value, 1);
-    return InterlockedCompareExchange((LONG*)&p->_Value, 1, 0);
+    return InterlockedCompareExchange(&p->_Value, 1, 0);
 }
 
 #define ATOMIC_ADD          InterlockedAdd

+ 1 - 1
base/hbase.c

@@ -414,7 +414,7 @@ size_t hv_parse_size(const char* str) {
             case 'K': case 'k': n <<= 10; break;
             case 'M': case 'm': n <<= 20; break;
             case 'G': case 'g': n <<= 30; break;
-            case 'T': case 't': n <<= 40; break;
+            case 'T': case 't': if(sizeof(size_t) > 5) n <<= 40; break;
             default:                      break;
             }
             size += n;

+ 3 - 1
base/rbtree.h

@@ -94,6 +94,8 @@ static inline struct page * rb_insert_page_cache(struct inode * inode,
 #ifndef _LINUX_RBTREE_H
 #define _LINUX_RBTREE_H
 
+#include <stdint.h> // for uintptr_t
+
 struct rb_node
 {
     struct rb_node *rb_parent;
@@ -111,7 +113,7 @@ struct rb_root
 
 #define RB_ROOT (struct rb_root){ (struct rb_node *)0, }
 #define rb_entry(ptr, type, member) \
-    ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
+    ((type *)((char *)(ptr)-(uintptr_t)(&((type *)0)->member)))
 
 #ifdef __cplusplus
 extern "C"

+ 1 - 0
evpp/EventLoop.h

@@ -169,6 +169,7 @@ public:
 
     void queueInLoop(Functor fn) {
         postEvent([fn](Event* ev) {
+            (void)(ev);
             if (fn) fn();
         });
     }

+ 1 - 0
evpp/TcpClient.h

@@ -171,6 +171,7 @@ public:
         uint32_t delay = reconn_setting_calc_delay(reconn_setting);
         hlogi("reconnect... cnt=%d, delay=%d", reconn_setting->cur_retry_cnt, reconn_setting->cur_delay);
         loop_->setTimeout(delay, [this](TimerID timerID){
+            (void)(timerID);
             startConnect();
         });
         return 0;

+ 10 - 0
http/server/HttpServer.cpp

@@ -163,6 +163,12 @@ static void loop_thread(void* userdata) {
     hlogi("EventLoop stopped, pid=%ld tid=%ld", hv_getpid(), hv_gettid());
 }
 
+#ifdef OS_WIN
+static void WINAPI loop_thread_stdcall(void* userdata) {
+    return loop_thread(userdata);
+}
+#endif
+
 /* @workflow:
  * http_server_run -> Listen -> master_workers_run / hthread_create ->
  * loop_thread -> accept -> EventLoop::run ->
@@ -215,7 +221,11 @@ int http_server_run(http_server_t* server, int wait) {
         // multi-threads
         if (server->worker_threads == 0) server->worker_threads = 1;
         for (int i = wait ? 1 : 0; i < server->worker_threads; ++i) {
+#ifdef OS_WIN
+            hthread_t thrd = hthread_create((hthread_routine)loop_thread_stdcall, server);
+#else
             hthread_t thrd = hthread_create((hthread_routine)loop_thread, server);
+#endif
             privdata->threads.push_back(thrd);
         }
         if (wait) {

+ 11 - 4
http/websocket_parser.c

@@ -225,10 +225,17 @@ size_t websocket_build_frame(char * frame, websocket_flags flags, const char mas
         body_offset = 4;
     } else {
         frame[1] |= 127;
-        frame[2] = (char) ((data_len >> 56) & 0xFF);
-        frame[3] = (char) ((data_len >> 48) & 0xFF);
-        frame[4] = (char) ((data_len >> 40) & 0xFF);
-        frame[5] = (char) ((data_len >> 32) & 0xFF);
+        if(sizeof(size_t) < 8) {
+            frame[2] = 0;
+            frame[3] = 0;
+            frame[4] = 0;
+            frame[5] = 0;
+        } else {
+            frame[2] = (char) ((data_len >> 56) & 0xFF);
+            frame[3] = (char) ((data_len >> 48) & 0xFF);
+            frame[4] = (char) ((data_len >> 40) & 0xFF);
+            frame[5] = (char) ((data_len >> 32) & 0xFF);
+        }
         frame[6] = (char) ((data_len >> 24) & 0xFF);
         frame[7] = (char) ((data_len >> 16) & 0xFF);
         frame[8] = (char) ((data_len >>  8) & 0xFF);

+ 35 - 0
hv.rc.in

@@ -0,0 +1,35 @@
+#include <winresrc.h>
+
+VS_VERSION_INFO     VERSIONINFO
+FILEVERSION         ${PROJECT_VERSION_MAJOR},${PROJECT_VERSION_MINOR},${PROJECT_VERSION_PATCH},0
+PRODUCTVERSION      ${PROJECT_VERSION_MAJOR},${PROJECT_VERSION_MINOR},${PROJECT_VERSION_PATCH},0
+FILEFLAGSMASK       VS_FFI_FILEFLAGSMASK
+#ifdef _DEBUG
+FILEFLAGS           VS_FF_DEBUG
+#else
+FILEFLAGS           0x0L
+#endif
+FILEOS              VOS_NT
+FILETYPE            VFT_DLL
+FILESUBTYPE         VFT2_UNKNOWN
+BEGIN
+    BLOCK "StringFileInfo"
+    BEGIN
+        BLOCK "080404B0"
+        BEGIN
+            VALUE "CompanyName", "https://github.com/ithewei/libhv"
+            VALUE "FileDescription", "${PROJECT_NAME} Library"
+            VALUE "FileVersion", "${PROJECT_VERSION}"
+            VALUE "InternalName", "${PROJECT_NAME}"
+            VALUE "LegalCopyright", "Copyright (C) 2020 ithewei All rights reserved."
+            VALUE "LegalTrademarks", "${PROJECT_NAME}"
+            VALUE "OriginalFilename", "${PROJECT_NAME}.dll"
+            VALUE "ProductName", "${PROJECT_NAME}"
+            VALUE "ProductVersion", "${PROJECT_VERSION}"
+        END
+    END
+    BLOCK "VarFileInfo"
+    BEGIN
+        VALUE "Translation", 0x0804, 0x04B0
+    END
+END