Coder Social home page Coder Social logo

uv-cpp's Introduction

uv-cpp

Github release Platform License Project Status: Active – The project has reached a stable, usable state and is being actively developed.


Language Translations:


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

Dependencies

Features

  • C++11 functional/bind style callback instead of C-style function pointer.
  • TCP and UDP wrapper.
  • DNSandHttp:DNS query and http support,Http routing based on radix tree.
  • TimerandTimerWheel:Heartbeat timeout judgment with time complexity of O(1).
  • Async:libuv async wrapper,but optimized the problem of calling multiple times but callback will only be called once.
  • PacketandPacketBuffer:Send and receive packet of Tcp data stream. Support custom data packet structure (such as uvnsq)
  • Log interface.

Build Instructions

  • VS2017 (windows)
  • Codeblocks (linux)
  • CMake (linux)

Benchmark

ping-pong VS boost.asio-1.67


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

size peer pack 1K bytes 2K bytes 4K bytes 8K bytes
uv-cpp 16138 kbyte 32071 kbyte 59264 kbyte 123813 kbyte
boost.asio 16119 kbyte 31566 kbyte 58322 kbyte 126210 kbyte

asio1


environment:i5-8265U + 4G memory + 4k bytes ping-pong

concurrency 10 100 1000 5000
uv-cpp 654282 kbyte 591869 kbyte 401500 kbyte 412855 kbyte
boost.asio 633818 kbyte 585716 kbyte 371386 kbyte 382402 kbyte

asio2

Apache bench VS nginx-1.14.2


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

1000 concurrency && 100000 request.
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.
API's document here.

uv-cpp's People

Contributors

adivinaelnombre avatar dselivanov avatar twoentartian avatar wlgq2 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.