中文 English
netpp is an event based, modern c++ TCP network library, based on reactor pattern and epoll, on Linux only, supporting features:
- linked buffer node
- none virtual user interface
- one loop per thread
- handle signal
- kick idle connection
- cmake >= 3.16.0
- c++17 supports
git clone https://github.com/netpp/netpp.git
git submodule init
git submodule update
mkdir build
cd build
cmake ../
make netpp -j8
Netpp provides non-virtual methods as events notify interface, define event handler and inject to netpp::Events.
class Echo {
public:
void onMessageReceived(std::shared_ptr<netpp::Channel> channel);
};
netpp::Events events(std::make_shared<Echo>());
An event loop dispatcher for create and dispatch event loop.
netpp::core::EventLoopDispatcher dispatcher;
Create a server, and assign event handler and dispatcher
netpp::TcpServer server(&dispatcher, netpp::Address("0.0.0.0", 12345), std::move(events));
server.listen();
or a client
netpp::Events<Echo> events(std::make_shared<Echo>());
netpp::TcpClient client(&dispatcher, netpp::Address("127.0.0.1", 12345), std::move(events));
client.connect();
Start event loop.
dispatcher.startLoop();
For more information, take a look at example/*.
Thanks jetbrains for provide opensource license to project netpp.