Kingpin is a C++ network library based on TCP/IP + epoll + pthread for the high concurrent servers and clients. Inspired by nginx / muduo.
-
One connected socket handled only by one thread.
-
Thread pool and IO multiplexing for both server's and client's concurrency.
-
IO threads compete for listening socket or target host pool in server and client.
-
Avoid excessive wrapper of classes and functions to get things complicated.
Please refer to: Quick Start
-
Linux: Support epoll, and glibc > 2.15 to avoid pthread_rwlock deadlock bug!
-
g++: Support C++ 11.
-
googletest / cmake / make.
-
IOHandler.h: Both server's and client's IO thread.
-
TPSharedData.h: Data shared among thread pool.
-
EpollTP.h: Thread pool initialized by IOHandler and TPSharedData.
-
AsyncLogger.h: Thread safe logger, using backend thread for asynchronous output, line buffered.
-
Buffer.h: IO Buffer pre-allocated on heap, support nonblock socket and disk fd. NOT thread safe.
-
Mutex.h: Easy to debug wrapper for read-write lock and recursive lock in libpthread.
-
Context.h: Function call timeout wrapper.
-
Utils.h: Some utility functions.
A wealth of cases:
-
Chinese Chess Game: Chess game server and client, also implements a high concurrency test client.
-
File Transfer: File transfer server and client, IO and exceptions are both well handled.
Build and run:
$ mkdir build && cd build
$ cmake .. && make
$ cd unittest && ctest
Architecture design for this repo is poor, although performance is very good.
A more well designed repo that have similar function : https://github.com/GeniusDai/cppev