Home

Awesome

uv-cpp

<a href="https://github.com/wlgq2/uv-cpp/releases"><img src="https://img.shields.io/github/release/wlgq2/uv-cpp.svg" alt="Github release"></a> Platform License Project Status: Active – The project has reached a stable, usable state and is being actively developed.

<br>Language Translations:</br>


uv-cpp is a simple interface, high-performance network library based on C++11.

Dependencies

Features


Build Instructions


Benchmark

ping-pong VS boost.asio-1.67

<br>environment:Intel Core i5 8265U + debian8 + gcc8.3.0 + libuv1.30.0 + '-O2'</br>

size peer pack1K bytes2K bytes4K bytes8K bytes
uv-cpp16138 kbyte32071 kbyte59264 kbyte123813 kbyte
boost.asio16119 kbyte31566 kbyte58322 kbyte126210 kbyte

asio1

<br>environment:i5-8265U + 4G memory + 4k bytes ping-pong</br>

concurrency1010010005000
uv-cpp654282 kbyte591869 kbyte401500 kbyte412855 kbyte
boost.asio633818 kbyte585716 kbyte371386 kbyte382402 kbyte

asio2

Apache bench VS nginx-1.14.2

<br>environment:Intel Core i5 8265U + debian8 + gcc8.3.0 + libuv1.30.0 + '-O2'</br> <br>1000 concurrency && 100000 request.</br> uv_http nginx_http

Quick start

A simple echo server

#include <iostream>
#include <uv/include/uv11.h>

int main(int argc, char** args)
{
    uv::EventLoop* loop = uv::EventLoop::DefaultLoop();
	
    uv::TcpServer server(loop);
    server.setMessageCallback([](uv::TcpConnectionPtr ptr,const char* data, ssize_t size)
    {
        ptr->write(data, size, nullptr);
    });
    //server.setTimeout(60); //heartbeat timeout.
	
    uv::SocketAddr addr("0.0.0.0", 10005, uv::SocketAddr::Ipv4);
    server.bindAndListen(addr);
    loop->run();
}

A simple http service router which based on radix tree.

int main(int argc, char** args)
{
    uv::EventLoop loop;
    uv::http::HttpServer::SetBufferMode(uv::GlobalConfig::BufferMode::CycleBuffer);

    uv::http::HttpServer server(&loop);
	
    //example:  127.0.0.1:10010/test
    server.Get("/test",std::bind(&func1,std::placeholders::_1,std::placeholders::_2));
    
    //example:  127.0.0.1:10010/some123abc
    server.Get("/some*",std::bind(&func2, std::placeholders::_1, std::placeholders::_2));
    
    //example:  127.0.0.1:10010/value:1234
    server.Get("/value:",std::bind(&func3, std::placeholders::_1, std::placeholders::_2));
    
    //example:  127.0.0.1:10010/sum?param1=100&param2=23
    server.Get("/sum",std::bind(&func4, std::placeholders::_1, std::placeholders::_2));
    
    uv::SocketAddr addr("127.0.0.1", 10010);
    server.bindAndListen(addr);
    loop.run();
}

More examples here. <br>API's document here. </br>