diff --git a/CMakeLists.txt b/CMakeLists.txt index ff1f1fa3f..9b9aae4a8 100644 --- a/CMakeLists.txt +++ b/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 $ DESTINATION bin OPTIONAL) +endif() + install(FILES ${LIBHV_HEADERS} DESTINATION include/hv) install(EXPORT libhvConfig DESTINATION lib/cmake/libhv) diff --git a/base/hatomic.h b/base/hatomic.h index 431dd5872..b3533dbcc 100644 --- a/base/hatomic.h +++ b/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 diff --git a/base/hbase.c b/base/hbase.c index db834c331..583161271 100644 --- a/base/hbase.c +++ b/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; diff --git a/base/rbtree.h b/base/rbtree.h index 602390a2f..7e38af290 100644 --- a/base/rbtree.h +++ b/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 // 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" diff --git a/evpp/EventLoop.h b/evpp/EventLoop.h index 40d24c256..e21ee1d33 100644 --- a/evpp/EventLoop.h +++ b/evpp/EventLoop.h @@ -169,6 +169,7 @@ class EventLoop : public Status { void queueInLoop(Functor fn) { postEvent([fn](Event* ev) { + (void)(ev); if (fn) fn(); }); } diff --git a/evpp/TcpClient.h b/evpp/TcpClient.h index be19cf294..e355b61d3 100644 --- a/evpp/TcpClient.h +++ b/evpp/TcpClient.h @@ -171,6 +171,7 @@ class TcpClientEventLoopTmpl { 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; diff --git a/http/server/HttpServer.cpp b/http/server/HttpServer.cpp index 9e73608b0..eff0a865c 100644 --- a/http/server/HttpServer.cpp +++ b/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) { diff --git a/http/websocket_parser.c b/http/websocket_parser.c index 96baf2035..c6f5670d7 100644 --- a/http/websocket_parser.c +++ b/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); diff --git a/hv.rc.in b/hv.rc.in new file mode 100644 index 000000000..62b9758b0 --- /dev/null +++ b/hv.rc.in @@ -0,0 +1,35 @@ +#include + +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