Mukachi / netpp

An event based, modern c++ TCP network library on Linux

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

netpp

中文 English

What is netpp

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

Dependent libs

How to compile

Requires

  • cmake >= 3.16.0
  • c++17 supports

Build with cmake

git clone https://github.com/netpp/netpp.git
git submodule init
git submodule update
mkdir build
cd build
cmake ../
make netpp -j8

Quick start

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.

About

An event based, modern c++ TCP network library on Linux

License:GNU General Public License v3.0


Languages

Language:C++ 98.5%Language:CMake 1.5%