A TCP network library implemented in C++11.
- Clone the code and build:
$ git clone https://github.com/WineChord/chtho.git
$ cd chtho
$ make
- Run the simple echo server and client examples:
$ ./build/bin/echoserver_test 5 # thread pool size (i.e. # of sub Reactors)
$ # inside another terminal 
$ ./build/bin/echoclient_test 127.0.0.1 3 # server ip and number of clients 
$ # then the message of 'hello' and 'world' will bump between 
$ # client and server infinitely 
- 
time - Timestamp: Provide basic utilities to provide current time and its conversions.
- TimeZone: Convert from Coordinated Universal Time to local time.
 
- 
logging - Loggerand- LogStream: front end of the logging system, used directly by the user.
- AsyncLogging,- LogFileand- FileUtil: back end of the logging system, asynchronously flush the data to disk and conditionally roll the log.
 
- 
threading - MutexLock,- MutexLockGuard,- Conditionand- CountDownLatch: encapsulated synchronization utilities.
- Threadand- ThreadPool: thread utilities based on pthread
 
- 
timers - Timerand- TimerID: record timestamp and callback function.
- TimerQueue: add/remove timers and find expired timers using balanced binary tree.
 
- 
networking - Channel: important abstraction provided for file descriptors and its relating events and corresponding callback functions.
- EventLoop: core class that demonstrates the Reactor pattern.
- EventLoopThread: encapsulates the eventloop in a thread, ensures 'one loop per thread'
- EventLoopThreadPool: starts a main eventloop thread acting as the main Reactor (usually used to monitor the listening socket) and a bunch of other eventloop thread acting as the sub Reactors (usually used to monitor read/write events happened on the connecting sockets).
- poller:
Poller: base class providing the interface of polling, usesChannelto manage the events and callback functions of file descritpors.Poll: An implementation ofPollerusingpoll(2).EPoll: An implementation ofPollerusingepoll(2), level-triggered.
- Buffer: used by- TcpConnectionto allow partial read/write.
- TcpConnection: manages read/write/close/error events happened on the connecting file descriptors, uses- Bufferto read/write data.
- Acceptor: created in- TcpServer, encapsulates the- socket,- bind,- listenand- acceptsteps. Inside- Acceptor::listen, it will pass the connection socket file descriptor returned by- acceptto the new connection callback function provided by- TcpServer.- TcpServerfinds a thread from thread pool for this new connection fd and creates a- TcpConnectionobject.- TcpConnectionwill register the connection channel (created upon connection fd) with the poller inside the eventloop which is dispatched eariler inside- TcpServerand then starts to handle events happened on the connection channel (through the registed callback functions on the channel).
- TcpServer: encapsulates a- EventLoopThreadPooland- Acceptor.- Acceptorwill handle- socket,- bind,- listenand- acceptsteps.- TcpServer's main role is dispatch the new connections to threads inside eventloop thread pool. It also provides the connection callback and message callback interface to the user.
- Connector: works for- TcpClient, encapsulates the- socketand- connectsteps. Depending on the return value of- ::connect, it will use a channel to detect whether the connection socket is available for writing. If it is, this channel for the socket is removed and the socket file descriptor is passed to new conection callback function provided by- TcpClient.- TcpClientwill use the socket file descriptor to create a new- TcpConnection. Then the- TcpConnectionwill handle the reading/writing event on the connection file descriptor. (the whole process is a little similar to- Acceptor)
- TcpClient: encapsulates a- EventLoopand- Connector. Similar to- TcpServer, it creates a new- TcpConnectionusing the file descriptor provided by the- Connection. It also provides the connection callback and message callback interface to the user.
- InetAddr: encapsulates Internet address.
- Socket: encapsulates socket related information.
 
development history: logger/logstream -> threading -> time/timer -> eventloop/thread/threadpool/poller/channel -> buffer/tcpconnection/acceptor/tcpserver -> connector/tcpclient -> logfile/asynclogging -> ???
- HTTP server
- protobuf
- protorpc
MIT License
This project learns massively from muduo.