Skip to content

Commit

Permalink
New feature: rudp WITH_KCP
Browse files Browse the repository at this point in the history
  • Loading branch information
ithewei committed Nov 24, 2021
1 parent ac88717 commit 57e0211
Show file tree
Hide file tree
Showing 25 changed files with 2,311 additions and 42 deletions.
12 changes: 12 additions & 0 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ make libhv

## options

### compile without c++
```
./configure --without-evpp
make clean && make
```

### compile WITH_OPENSSL
Enable SSL in libhv is so easy, just only two apis:
```
Expand Down Expand Up @@ -126,3 +132,9 @@ make clean && make
bin/httpd -s restart -d
bin/curl -v http://localhost:8080 --http2
```

### compile WITH_KCP
```
./configure --with-kcp
make clean && make
```
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ option(WITH_OPENSSL "with openssl library" OFF)
option(WITH_GNUTLS "with gnutls library" OFF)
option(WITH_MBEDTLS "with mbedtls library" OFF)

option(WITH_KCP "with kcp" OFF)

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}")
include(utils)
include(vars)
Expand Down Expand Up @@ -148,8 +150,12 @@ if(APPLE)
endif()

# see Makefile
set(ALL_SRCDIRS . base ssl event util cpputil evpp protocol http http/client http/server)
set(LIBHV_SRCDIRS . base ssl event util)
set(ALL_SRCDIRS . base ssl event event/kcp util cpputil evpp protocol http http/client http/server)
set(CORE_SRCDIRS . base ssl event)
if(WITH_KCP)
set(CORE_SRCDIRS ${CORE_SRCDIRS} event/kcp)
endif()
set(LIBHV_SRCDIRS ${CORE_SRCDIRS} util)
set(LIBHV_HEADERS hv.h hconfig.h hexport.h)
set(LIBHV_HEADERS ${LIBHV_HEADERS} ${BASE_HEADERS} ${SSL_HEADERS} ${EVENT_HEADERS} ${UTIL_HEADERS})

Expand Down
61 changes: 33 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ include config.mk
include Makefile.vars

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

LIBHV_SRCDIRS = . base ssl event util
LIBHV_SRCDIRS = $(CORE_SRCDIRS) util
LIBHV_HEADERS = hv.h hconfig.h hexport.h
LIBHV_HEADERS += $(BASE_HEADERS) $(SSL_HEADERS) $(EVENT_HEADERS) $(UTIL_HEADERS)

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

htimer_test: prepare
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/htimer_test.c"
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/htimer_test.c"

hloop_test: prepare
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/hloop_test.c"
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/hloop_test.c"

tcp_echo_server: prepare
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/tcp_echo_server.c"
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/tcp_echo_server.c"

tcp_chat_server: prepare
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/tcp_chat_server.c"
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/tcp_chat_server.c"

tcp_proxy_server: prepare
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/tcp_proxy_server.c"
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/tcp_proxy_server.c"

udp_echo_server: prepare
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/udp_echo_server.c"
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/udp_echo_server.c"

udp_proxy_server: prepare
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/udp_proxy_server.c"
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/udp_proxy_server.c"

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

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

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

nc: prepare
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/nc.c"
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/nc.c"

nmap: prepare
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event cpputil examples/nmap" DEFINES="PRINT_DEBUG"
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) cpputil examples/nmap" DEFINES="PRINT_DEBUG"

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

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

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

curl: prepare
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event util cpputil evpp http http/client" SRCS="examples/curl.cpp"
# $(MAKEF) TARGET=$@ SRCDIRS=". base ssl event util cpputil evpp http http/client" SRCS="examples/curl.cpp" WITH_CURL=yes
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) util cpputil evpp http http/client" SRCS="examples/curl.cpp"
# $(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) util cpputil evpp http http/client" SRCS="examples/curl.cpp" WITH_CURL=yes

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

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

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

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

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

jsonrpc: jsonrpc_client jsonrpc_server

jsonrpc_client: prepare
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/jsonrpc/jsonrpc_client.c examples/jsonrpc/jsonrpc.c examples/jsonrpc/cJSON.c"
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/jsonrpc/jsonrpc_client.c examples/jsonrpc/jsonrpc.c examples/jsonrpc/cJSON.c"

jsonrpc_server: prepare
$(RM) examples/jsonrpc/*.o
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event" SRCS="examples/jsonrpc/jsonrpc_server.c examples/jsonrpc/jsonrpc.c examples/jsonrpc/cJSON.c"
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS)" SRCS="examples/jsonrpc/jsonrpc_server.c examples/jsonrpc/jsonrpc.c examples/jsonrpc/cJSON.c"

protorpc: protorpc_client protorpc_server

protorpc_protoc:
bash examples/protorpc/proto/protoc.sh

protorpc_client: prepare protorpc_protoc
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event cpputil evpp examples/protorpc/generated" \
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) cpputil evpp examples/protorpc/generated" \
SRCS="examples/protorpc/protorpc_client.cpp examples/protorpc/protorpc.c" \
LIBS="protobuf"

protorpc_server: prepare protorpc_protoc
$(RM) examples/protorpc/*.o
$(MAKEF) TARGET=$@ SRCDIRS=". base ssl event cpputil evpp examples/protorpc/generated" \
$(MAKEF) TARGET=$@ SRCDIRS="$(CORE_SRCDIRS) cpputil evpp examples/protorpc/generated" \
SRCS="examples/protorpc/protorpc_server.cpp examples/protorpc/protorpc.c" \
LIBS="protobuf"

unittest: prepare
$(CC) -g -Wall -O0 -std=c99 -I. -Ibase -o bin/rbtree_test unittest/rbtree_test.c base/rbtree.c
$(CC) -g -Wall -O0 -std=c99 -I. -Ibase -o bin/mkdir_p unittest/mkdir_test.c base/hbase.c
$(CC) -g -Wall -O0 -std=c99 -I. -Ibase -o bin/rmdir_p unittest/rmdir_test.c base/hbase.c
$(CC) -g -Wall -O0 -std=c99 -I. -Ibase -o bin/date unittest/date_test.c base/htime.c
Expand Down
1 change: 1 addition & 0 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- 高性能事件循环(网络IO事件、定时器事件、空闲事件、自定义事件)
- TCP/UDP服务端/客户端/代理
- TCP支持心跳、转发、拆包、多线程安全write和close等特性
- 可靠UDP支持: WITH_KCP
- SSL/TLS加密通信(可选WITH_OPENSSL、WITH_GNUTLS、WITH_MBEDTLS)
- HTTP服务端/客户端(支持https http1/x http2 grpc)
- HTTP支持静态文件服务、目录服务、同步/异步API处理函数
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ but simpler api and richer protocols.
## ✨ Features

- Cross-platform (Linux, Windows, MacOS, Solaris)
- EventLoop (IO, timer, idle, custom)
- High-performance EventLoop (IO, timer, idle, custom)
- TCP/UDP client/server/proxy
- TCP supports heartbeat, upstream, unpack, MultiThread-safe write and close, etc.
- RUDP support: WITH_KCP
- SSL/TLS support: (via WITH_OPENSSL or WITH_GNUTLS or WITH_MBEDTLS)
- HTTP client/server (support https http1/x http2 grpc)
- HTTP static file service, indexof service, sync/async API handler
Expand Down
3 changes: 3 additions & 0 deletions config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ WITH_NGHTTP2=no
WITH_OPENSSL=no
WITH_GNUTLS=no
WITH_MBEDTLS=no

# rudp
WITH_KCP=no
3 changes: 2 additions & 1 deletion config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ WITH_NGHTTP2=no
WITH_OPENSSL=no
WITH_GNUTLS=no
WITH_MBEDTLS=no
CONFIG_DATE=20210817
WITH_KCP=no
CONFIG_DATE=20211124
4 changes: 4 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ dependencies:
--with-gnutls compile with gnutls? (DEFAULT: $WITH_GNUTLS)
--with-mbedtls compile with mbedtls? (DEFAULT: $WITH_MBEDTLS)
rudp:
--with-kcp compile with kcp? (DEFAULT: $WITH_KCP)
END
}

Expand Down Expand Up @@ -250,6 +253,7 @@ option=WITH_GNUTLS && check_option
option=WITH_MBEDTLS && check_option
option=ENABLE_UDS && check_option
option=USE_MULTIMAP && check_option
option=WITH_KCP && check_option

# end confile
cat << END >> $confile
Expand Down
7 changes: 6 additions & 1 deletion docs/PLAN.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## Done

- base: cross platfrom infrastructure
- event: select/poll/epoll/kqueue/port
- ssl: openssl/guntls/mbedtls
- evpp: c++ EventLoop interface similar to muduo and evpp
- http client/server: include https http1/x http2
- websocket client/server
Expand All @@ -18,5 +20,8 @@
- lua binding
- js binding
- hrpc = libhv + protobuf
- reliable udp: FEC, ARQ, KCP, UDT, QUIC
- rudp: FEC, ARQ, KCP, UDT, QUIC
- have a taste of io_uring
- coroutine
- IM-libhv
- GameServer-libhv
2 changes: 2 additions & 0 deletions event/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
├── hloop.h 事件循环模块对外头文件
├── hevent.h 事件结构体定义
├── nlog.h 网络日志
├── unpack.h 拆包
├── rudp.h 可靠UDP
├── iowatcher.h IO多路复用统一抽象接口
├── select.c EVENT_SELECT实现
├── poll.c EVENT_POLL实现
Expand Down
Loading

0 comments on commit 57e0211

Please sign in to comment.