Skip to content

Commit 1e3dd55

Browse files
authored
add windows dll versions resource (#712)
add cmake install windows debug pdb fix known compilation warnings
1 parent 3d0233d commit 1e3dd55

File tree

9 files changed

+73
-8
lines changed

9 files changed

+73
-8
lines changed

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ if(WITH_MQTT)
238238
endif()
239239

240240
list_source_directories(LIBHV_SRCS ${LIBHV_SRCDIRS})
241+
if(WIN32)
242+
set(CMAKE_RC_FLAGS_DEBUG -D_DEBUG)
243+
configure_file(${PROJECT_SOURCE_DIR}/${PROJECT_NAME}.rc.in ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.rc)
244+
list(APPEND LIBHV_SRCS ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.rc)
245+
endif()
241246

242247
file(INSTALL ${LIBHV_HEADERS} DESTINATION include/hv)
243248
file(INSTALL ${LIBHV_HEADERS} DESTINATION ${PROJECT_SOURCE_DIR}/include/hv)
@@ -268,6 +273,10 @@ if(BUILD_STATIC)
268273
add_custom_target(libhv_static DEPENDS hv_static)
269274
endif()
270275

276+
if(WIN32)
277+
install(FILES $<TARGET_PDB_FILE:${PROJECT_NAME}> DESTINATION bin OPTIONAL)
278+
endif()
279+
271280
install(FILES ${LIBHV_HEADERS} DESTINATION include/hv)
272281
install(EXPORT libhvConfig DESTINATION lib/cmake/libhv)
273282

base/hatomic.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ typedef volatile long long atomic_llong;
4242
typedef volatile unsigned long long atomic_ullong;
4343
typedef volatile size_t atomic_size_t;
4444

45-
typedef struct atomic_flag { atomic_bool _Value; } atomic_flag;
45+
typedef struct atomic_flag { atomic_long _Value; } atomic_flag;
4646

4747
#ifdef _WIN32
4848

4949
#define ATOMIC_FLAG_TEST_AND_SET atomic_flag_test_and_set
5050
static inline bool atomic_flag_test_and_set(atomic_flag* p) {
5151
// return InterlockedIncrement((LONG*)&p->_Value, 1);
52-
return InterlockedCompareExchange((LONG*)&p->_Value, 1, 0);
52+
return InterlockedCompareExchange(&p->_Value, 1, 0);
5353
}
5454

5555
#define ATOMIC_ADD InterlockedAdd

base/hbase.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ size_t hv_parse_size(const char* str) {
414414
case 'K': case 'k': n <<= 10; break;
415415
case 'M': case 'm': n <<= 20; break;
416416
case 'G': case 'g': n <<= 30; break;
417-
case 'T': case 't': n <<= 40; break;
417+
case 'T': case 't': if(sizeof(size_t) > 5) n <<= 40; break;
418418
default: break;
419419
}
420420
size += n;

base/rbtree.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ static inline struct page * rb_insert_page_cache(struct inode * inode,
9494
#ifndef _LINUX_RBTREE_H
9595
#define _LINUX_RBTREE_H
9696

97+
#include <stdint.h> // for uintptr_t
98+
9799
struct rb_node
98100
{
99101
struct rb_node *rb_parent;
@@ -111,7 +113,7 @@ struct rb_root
111113

112114
#define RB_ROOT (struct rb_root){ (struct rb_node *)0, }
113115
#define rb_entry(ptr, type, member) \
114-
((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
116+
((type *)((char *)(ptr)-(uintptr_t)(&((type *)0)->member)))
115117

116118
#ifdef __cplusplus
117119
extern "C"

evpp/EventLoop.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ class EventLoop : public Status {
169169

170170
void queueInLoop(Functor fn) {
171171
postEvent([fn](Event* ev) {
172+
(void)(ev);
172173
if (fn) fn();
173174
});
174175
}

evpp/TcpClient.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ class TcpClientEventLoopTmpl {
171171
uint32_t delay = reconn_setting_calc_delay(reconn_setting);
172172
hlogi("reconnect... cnt=%d, delay=%d", reconn_setting->cur_retry_cnt, reconn_setting->cur_delay);
173173
loop_->setTimeout(delay, [this](TimerID timerID){
174+
(void)(timerID);
174175
startConnect();
175176
});
176177
return 0;

http/server/HttpServer.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ static void loop_thread(void* userdata) {
163163
hlogi("EventLoop stopped, pid=%ld tid=%ld", hv_getpid(), hv_gettid());
164164
}
165165

166+
#ifdef OS_WIN
167+
static void WINAPI loop_thread_stdcall(void* userdata) {
168+
return loop_thread(userdata);
169+
}
170+
#endif
171+
166172
/* @workflow:
167173
* http_server_run -> Listen -> master_workers_run / hthread_create ->
168174
* loop_thread -> accept -> EventLoop::run ->
@@ -215,7 +221,11 @@ int http_server_run(http_server_t* server, int wait) {
215221
// multi-threads
216222
if (server->worker_threads == 0) server->worker_threads = 1;
217223
for (int i = wait ? 1 : 0; i < server->worker_threads; ++i) {
224+
#ifdef OS_WIN
225+
hthread_t thrd = hthread_create((hthread_routine)loop_thread_stdcall, server);
226+
#else
218227
hthread_t thrd = hthread_create((hthread_routine)loop_thread, server);
228+
#endif
219229
privdata->threads.push_back(thrd);
220230
}
221231
if (wait) {

http/websocket_parser.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,17 @@ size_t websocket_build_frame(char * frame, websocket_flags flags, const char mas
225225
body_offset = 4;
226226
} else {
227227
frame[1] |= 127;
228-
frame[2] = (char) ((data_len >> 56) & 0xFF);
229-
frame[3] = (char) ((data_len >> 48) & 0xFF);
230-
frame[4] = (char) ((data_len >> 40) & 0xFF);
231-
frame[5] = (char) ((data_len >> 32) & 0xFF);
228+
if(sizeof(size_t) < 8) {
229+
frame[2] = 0;
230+
frame[3] = 0;
231+
frame[4] = 0;
232+
frame[5] = 0;
233+
} else {
234+
frame[2] = (char) ((data_len >> 56) & 0xFF);
235+
frame[3] = (char) ((data_len >> 48) & 0xFF);
236+
frame[4] = (char) ((data_len >> 40) & 0xFF);
237+
frame[5] = (char) ((data_len >> 32) & 0xFF);
238+
}
232239
frame[6] = (char) ((data_len >> 24) & 0xFF);
233240
frame[7] = (char) ((data_len >> 16) & 0xFF);
234241
frame[8] = (char) ((data_len >> 8) & 0xFF);

hv.rc.in

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <winresrc.h>
2+
3+
VS_VERSION_INFO VERSIONINFO
4+
FILEVERSION ${PROJECT_VERSION_MAJOR},${PROJECT_VERSION_MINOR},${PROJECT_VERSION_PATCH},0
5+
PRODUCTVERSION ${PROJECT_VERSION_MAJOR},${PROJECT_VERSION_MINOR},${PROJECT_VERSION_PATCH},0
6+
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
7+
#ifdef _DEBUG
8+
FILEFLAGS VS_FF_DEBUG
9+
#else
10+
FILEFLAGS 0x0L
11+
#endif
12+
FILEOS VOS_NT
13+
FILETYPE VFT_DLL
14+
FILESUBTYPE VFT2_UNKNOWN
15+
BEGIN
16+
BLOCK "StringFileInfo"
17+
BEGIN
18+
BLOCK "080404B0"
19+
BEGIN
20+
VALUE "CompanyName", "https://github.com/ithewei/libhv"
21+
VALUE "FileDescription", "${PROJECT_NAME} Library"
22+
VALUE "FileVersion", "${PROJECT_VERSION}"
23+
VALUE "InternalName", "${PROJECT_NAME}"
24+
VALUE "LegalCopyright", "Copyright (C) 2020 ithewei All rights reserved."
25+
VALUE "LegalTrademarks", "${PROJECT_NAME}"
26+
VALUE "OriginalFilename", "${PROJECT_NAME}.dll"
27+
VALUE "ProductName", "${PROJECT_NAME}"
28+
VALUE "ProductVersion", "${PROJECT_VERSION}"
29+
END
30+
END
31+
BLOCK "VarFileInfo"
32+
BEGIN
33+
VALUE "Translation", 0x0804, 0x04B0
34+
END
35+
END

0 commit comments

Comments
 (0)