Skip to content

Commit 57e0211

Browse files
author
ithewei
committed
New feature: rudp WITH_KCP
1 parent ac88717 commit 57e0211

File tree

25 files changed

+2311
-42
lines changed

25 files changed

+2311
-42
lines changed

BUILD.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ make libhv
9090

9191
## options
9292

93+
### compile without c++
94+
```
95+
./configure --without-evpp
96+
make clean && make
97+
```
98+
9399
### compile WITH_OPENSSL
94100
Enable SSL in libhv is so easy, just only two apis:
95101
```
@@ -126,3 +132,9 @@ make clean && make
126132
bin/httpd -s restart -d
127133
bin/curl -v http://localhost:8080 --http2
128134
```
135+
136+
### compile WITH_KCP
137+
```
138+
./configure --with-kcp
139+
make clean && make
140+
```

CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ option(WITH_OPENSSL "with openssl library" OFF)
2828
option(WITH_GNUTLS "with gnutls library" OFF)
2929
option(WITH_MBEDTLS "with mbedtls library" OFF)
3030

31+
option(WITH_KCP "with kcp" OFF)
32+
3133
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}")
3234
include(utils)
3335
include(vars)
@@ -148,8 +150,12 @@ if(APPLE)
148150
endif()
149151

150152
# see Makefile
151-
set(ALL_SRCDIRS . base ssl event util cpputil evpp protocol http http/client http/server)
152-
set(LIBHV_SRCDIRS . base ssl event util)
153+
set(ALL_SRCDIRS . base ssl event event/kcp util cpputil evpp protocol http http/client http/server)
154+
set(CORE_SRCDIRS . base ssl event)
155+
if(WITH_KCP)
156+
set(CORE_SRCDIRS ${CORE_SRCDIRS} event/kcp)
157+
endif()
158+
set(LIBHV_SRCDIRS ${CORE_SRCDIRS} util)
153159
set(LIBHV_HEADERS hv.h hconfig.h hexport.h)
154160
set(LIBHV_HEADERS ${LIBHV_HEADERS} ${BASE_HEADERS} ${SSL_HEADERS} ${EVENT_HEADERS} ${UTIL_HEADERS})
155161

Makefile

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ include config.mk
22
include Makefile.vars
33

44
MAKEF=$(MAKE) -f Makefile.in
5-
ALL_SRCDIRS=. base ssl event util cpputil evpp protocol http http/client http/server
5+
ALL_SRCDIRS=. base ssl event event/kcp util cpputil evpp protocol http http/client http/server
6+
CORE_SRCDIRS=. base ssl event
7+
ifeq ($(WITH_KCP), yes)
8+
CORE_SRCDIRS += event/kcp
9+
endif
610

7-
LIBHV_SRCDIRS = . base ssl event util
11+
LIBHV_SRCDIRS = $(CORE_SRCDIRS) util
812
LIBHV_HEADERS = hv.h hconfig.h hexport.h
913
LIBHV_HEADERS += $(BASE_HEADERS) $(SSL_HEADERS) $(EVENT_HEADERS) $(UTIL_HEADERS)
1014

@@ -75,96 +79,97 @@ hmain_test: prepare
7579
$(MAKEF) TARGET=$@ SRCDIRS=". base cpputil" SRCS="examples/hmain_test.cpp"
7680

7781
htimer_test: prepare
78-
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/htimer_test.c"
82+
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/htimer_test.c"
7983

8084
hloop_test: prepare
81-
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/hloop_test.c"
85+
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/hloop_test.c"
8286

8387
tcp_echo_server: prepare
84-
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/tcp_echo_server.c"
88+
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/tcp_echo_server.c"
8589

8690
tcp_chat_server: prepare
87-
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/tcp_chat_server.c"
91+
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/tcp_chat_server.c"
8892

8993
tcp_proxy_server: prepare
90-
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/tcp_proxy_server.c"
94+
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/tcp_proxy_server.c"
9195

9296
udp_echo_server: prepare
93-
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/udp_echo_server.c"
97+
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/udp_echo_server.c"
9498

9599
udp_proxy_server: prepare
96-
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/udp_proxy_server.c"
100+
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/udp_proxy_server.c"
97101

98102
multi-acceptor-processes: prepare
99-
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/multi-thread/multi-acceptor-processes.c"
103+
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/multi-thread/multi-acceptor-processes.c"
100104

101105
multi-acceptor-threads: prepare
102-
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/multi-thread/multi-acceptor-threads.c"
106+
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/multi-thread/multi-acceptor-threads.c"
103107

104108
one-acceptor-multi-workers: prepare
105-
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/multi-thread/one-acceptor-multi-workers.c"
109+
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/multi-thread/one-acceptor-multi-workers.c"
106110

107111
nc: prepare
108-
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/nc.c"
112+
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/nc.c"
109113

110114
nmap: prepare
111-
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event cpputil examples/nmap" DEFINES="PRINT_DEBUG"
115+
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) cpputil examples/nmap" DEFINES="PRINT_DEBUG"
112116

113117
wrk: prepare
114-
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event util cpputil evpp http" SRCS="examples/wrk.cpp"
118+
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) util cpputil evpp http" SRCS="examples/wrk.cpp"
115119

116120
httpd: prepare
117121
$(RM) examples/httpd/*.o
118-
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event util cpputil evpp http http/client http/server examples/httpd"
122+
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) util cpputil evpp http http/client http/server examples/httpd"
119123

120124
consul: prepare
121-
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event util cpputil evpp http http/client examples/consul" DEFINES="PRINT_DEBUG"
125+
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) util cpputil evpp http http/client examples/consul" DEFINES="PRINT_DEBUG"
122126

123127
curl: prepare
124-
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event util cpputil evpp http http/client" SRCS="examples/curl.cpp"
125-
# $(MAKEF) TARGET=$@ SRCDIRS=". base ssl event util cpputil evpp http http/client" SRCS="examples/curl.cpp" WITH_CURL=yes
128+
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) util cpputil evpp http http/client" SRCS="examples/curl.cpp"
129+
# $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) util cpputil evpp http http/client" SRCS="examples/curl.cpp" WITH_CURL=yes
126130

127131
wget: prepare
128-
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event util cpputil evpp http http/client" SRCS="examples/wget.cpp"
132+
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) util cpputil evpp http http/client" SRCS="examples/wget.cpp"
129133

130134
http_server_test: prepare
131-
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event util cpputil evpp http http/server" SRCS="examples/http_server_test.cpp"
135+
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) util cpputil evpp http http/server" SRCS="examples/http_server_test.cpp"
132136

133137
http_client_test: prepare
134-
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event util cpputil evpp http http/client" SRCS="examples/http_client_test.cpp"
138+
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) util cpputil evpp http http/client" SRCS="examples/http_client_test.cpp"
135139

136140
websocket_server_test: prepare
137-
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event util cpputil evpp http http/server" SRCS="examples/websocket_server_test.cpp"
141+
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) util cpputil evpp http http/server" SRCS="examples/websocket_server_test.cpp"
138142

139143
websocket_client_test: prepare
140-
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event util cpputil evpp http http/client" SRCS="examples/websocket_client_test.cpp"
144+
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) util cpputil evpp http http/client" SRCS="examples/websocket_client_test.cpp"
141145

142146
jsonrpc: jsonrpc_client jsonrpc_server
143147

144148
jsonrpc_client: prepare
145-
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/jsonrpc/jsonrpc_client.c examples/jsonrpc/jsonrpc.c examples/jsonrpc/cJSON.c"
149+
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/jsonrpc/jsonrpc_client.c examples/jsonrpc/jsonrpc.c examples/jsonrpc/cJSON.c"
146150

147151
jsonrpc_server: prepare
148152
$(RM) examples/jsonrpc/*.o
149-
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/jsonrpc/jsonrpc_server.c examples/jsonrpc/jsonrpc.c examples/jsonrpc/cJSON.c"
153+
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/jsonrpc/jsonrpc_server.c examples/jsonrpc/jsonrpc.c examples/jsonrpc/cJSON.c"
150154

151155
protorpc: protorpc_client protorpc_server
152156

153157
protorpc_protoc:
154158
bash examples/protorpc/proto/protoc.sh
155159

156160
protorpc_client: prepare protorpc_protoc
157-
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event cpputil evpp examples/protorpc/generated" \
161+
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) cpputil evpp examples/protorpc/generated" \
158162
SRCS="examples/protorpc/protorpc_client.cpp examples/protorpc/protorpc.c" \
159163
LIBS="protobuf"
160164

161165
protorpc_server: prepare protorpc_protoc
162166
$(RM) examples/protorpc/*.o
163-
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event cpputil evpp examples/protorpc/generated" \
167+
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) cpputil evpp examples/protorpc/generated" \
164168
SRCS="examples/protorpc/protorpc_server.cpp examples/protorpc/protorpc.c" \
165169
LIBS="protobuf"
166170

167171
unittest: prepare
172+
$(CC) -g -Wall -O0 -std=c99 -I. -Ibase -o bin/rbtree_test unittest/rbtree_test.c base/rbtree.c
168173
$(CC) -g -Wall -O0 -std=c99 -I. -Ibase -o bin/mkdir_p unittest/mkdir_test.c base/hbase.c
169174
$(CC) -g -Wall -O0 -std=c99 -I. -Ibase -o bin/rmdir_p unittest/rmdir_test.c base/hbase.c
170175
$(CC) -g -Wall -O0 -std=c99 -I. -Ibase -o bin/date unittest/date_test.c base/htime.c

README-CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
- 高性能事件循环(网络IO事件、定时器事件、空闲事件、自定义事件)
2626
- TCP/UDP服务端/客户端/代理
2727
- TCP支持心跳、转发、拆包、多线程安全write和close等特性
28+
- 可靠UDP支持: WITH_KCP
2829
- SSL/TLS加密通信(可选WITH_OPENSSL、WITH_GNUTLS、WITH_MBEDTLS)
2930
- HTTP服务端/客户端(支持https http1/x http2 grpc)
3031
- HTTP支持静态文件服务、目录服务、同步/异步API处理函数

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ but simpler api and richer protocols.
2424
## ✨ Features
2525

2626
- Cross-platform (Linux, Windows, MacOS, Solaris)
27-
- EventLoop (IO, timer, idle, custom)
27+
- High-performance EventLoop (IO, timer, idle, custom)
2828
- TCP/UDP client/server/proxy
2929
- TCP supports heartbeat, upstream, unpack, MultiThread-safe write and close, etc.
30+
- RUDP support: WITH_KCP
3031
- SSL/TLS support: (via WITH_OPENSSL or WITH_GNUTLS or WITH_MBEDTLS)
3132
- HTTP client/server (support https http1/x http2 grpc)
3233
- HTTP static file service, indexof service, sync/async API handler

config.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ WITH_NGHTTP2=no
3333
WITH_OPENSSL=no
3434
WITH_GNUTLS=no
3535
WITH_MBEDTLS=no
36+
37+
# rudp
38+
WITH_KCP=no

config.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ WITH_NGHTTP2=no
1616
WITH_OPENSSL=no
1717
WITH_GNUTLS=no
1818
WITH_MBEDTLS=no
19-
CONFIG_DATE=20210817
19+
WITH_KCP=no
20+
CONFIG_DATE=20211124

configure

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ dependencies:
3636
--with-gnutls compile with gnutls? (DEFAULT: $WITH_GNUTLS)
3737
--with-mbedtls compile with mbedtls? (DEFAULT: $WITH_MBEDTLS)
3838
39+
rudp:
40+
--with-kcp compile with kcp? (DEFAULT: $WITH_KCP)
41+
3942
END
4043
}
4144

@@ -250,6 +253,7 @@ option=WITH_GNUTLS && check_option
250253
option=WITH_MBEDTLS && check_option
251254
option=ENABLE_UDS && check_option
252255
option=USE_MULTIMAP && check_option
256+
option=WITH_KCP && check_option
253257

254258
# end confile
255259
cat << END >> $confile

docs/PLAN.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
## Done
22

3+
- base: cross platfrom infrastructure
34
- event: select/poll/epoll/kqueue/port
5+
- ssl: openssl/guntls/mbedtls
46
- evpp: c++ EventLoop interface similar to muduo and evpp
57
- http client/server: include https http1/x http2
68
- websocket client/server
@@ -18,5 +20,8 @@
1820
- lua binding
1921
- js binding
2022
- hrpc = libhv + protobuf
21-
- reliable udp: FEC, ARQ, KCP, UDT, QUIC
23+
- rudp: FEC, ARQ, KCP, UDT, QUIC
2224
- have a taste of io_uring
25+
- coroutine
26+
- IM-libhv
27+
- GameServer-libhv

event/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
├── hloop.h 事件循环模块对外头文件
66
├── hevent.h 事件结构体定义
77
├── nlog.h 网络日志
8+
├── unpack.h 拆包
9+
├── rudp.h 可靠UDP
810
├── iowatcher.h IO多路复用统一抽象接口
911
├── select.c EVENT_SELECT实现
1012
├── poll.c EVENT_POLL实现

0 commit comments

Comments
 (0)