Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions base/hatomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion base/hbase.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion base/rbtree.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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"
Expand Down
1 change: 1 addition & 0 deletions evpp/EventLoop.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ class EventLoop : public Status {

void queueInLoop(Functor fn) {
postEvent([fn](Event* ev) {
(void)(ev);
if (fn) fn();
});
}
Expand Down
1 change: 1 addition & 0 deletions evpp/TcpClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions http/server/HttpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down Expand Up @@ -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) {
Expand Down
15 changes: 11 additions & 4 deletions http/websocket_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
35 changes: 35 additions & 0 deletions hv.rc.in
Original file line number Diff line number Diff line change
@@ -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