epoll

1. epoll example in c

http://matrix207.github.io/2014/04/10/epoll-example-in-c/

2. C++ (Cpp) epoll_create1 Examples

https://cpp.hotexamples.com/examples/-/-/epoll_create1/cpp-epoll_create1-function-examples.html

3. SocketPP

https://github.com/shuai132/SocketPP

# Socket++

[![Build Status](https://www.travis-ci.org/shuai132/SocketPP.svg?branch=master)](https://www.travis-ci.org/shuai132/SocketPP)

a lightweight C++ TCP socket library, powered by epoll on Linux platform and kqueue on macOS/Unix.

## Features:
* High performance and high concurrenc benefit from epoll/kqueue
* Support send queue with thread safe
* Automatic memory management and ensure performance by c++ move semantics
* Multi-instance support
* Multiplatform support, Linux/macOS and most Unix-like OS.

## Requirements:
* C++11

## Build:
```bash
mkdir build && cd build && cmake .. && make
```

## Usage:
* simple echo server
```cpp
#include "SocketPP.h"

using namespace SocketPP;

int main() {
    const int port = 6000;
    TCPServer server(port);
    server.setRecvHandle([&] (const Message& message) {
        server.send(message);
    });
    return server.loop();
}
```
and then use nc tools, or run client example:
```bash
nc localhost 6000
```
or
```cpp
#include "SocketPP.h"

using namespace SocketPP;

int main() {
    const int port = 6000;
    TCPClient client("127.0.0.1", port);
    client.setConnHandle([&] (const TCPStream& stream) {
        client.send("hello");
    });
    client.setRecvHandle([&] (const Message& message) {
        printf("on receive: msg:%s", message.rawMsg.toString().c_str());
    });
    return client.loop();
}
```

 
https://stackoverflow.com/questions/51777259/how-to-code-an-epoll-based-sockets-client-in-c
https://github.com/shuveb/zerohttpd/tree/master/07_epoll
https://github.com/RajivKurian/epoll-example

原文地址:https://www.cnblogs.com/dong1/p/11814263.html