Giter Site home page Giter Site logo

rpclib / rpclib Goto Github PK

View Code? Open in Web Editor NEW
1.6K 1.6K 377.0 3.36 MB

rpclib is a modern C++ msgpack-RPC server and client library

Home Page: http://rpclib.net

License: Other

Python 0.16% CMake 0.61% C++ 93.98% Shell 0.02% C 5.18% PowerShell 0.04%
cplusplus cplusplus-14 cpp cpp14 msgpack rpc

rpclib's Introduction

rpclib MIT Build Status Build status Coverage Status Coverity Gitter

Status

rpclib is looking for maintainers

If you're looking for a similar library with support for JSON-RPC and async operations, check out packio.

Overview

rpclib is a RPC library for C++, providing both a client and server implementation. It is built using modern C++14, and as such, requires a recent compiler. Main highlights:

  • Expose functions of your program to be called via RPC (from any language implementing msgpack-rpc)
  • Call functions through RPC (of programs written in any language)
  • No IDL to learn
  • No code generation step to integrate in your build, just C++

Look&feel

Server

#include <iostream>
#include "rpc/server.h"

void foo() {
    std::cout << "foo was called!" << std::endl;
}

int main(int argc, char *argv[]) {
    // Creating a server that listens on port 8080
    rpc::server srv(8080);

    // Binding the name "foo" to free function foo.
    // note: the signature is automatically captured
    srv.bind("foo", &foo);

    // Binding a lambda function to the name "add".
    srv.bind("add", [](int a, int b) {
        return a + b;
    });

    // Run the server loop.
    srv.run();

    return 0;
}

When srv.run() is called, rpclib starts the server loop which listens to incoming connections and tries to dispatch calls to the bound functions. The functions are called from the thread where run was called from. There is also async_run that spawns worker threads and returns immediately.

Client

#include <iostream>
#include "rpc/client.h"

int main() {
    // Creating a client that connects to the localhost on port 8080
    rpc::client client("127.0.0.1", 8080);

    // Calling a function with paramters and converting the result to int
    auto result = client.call("add", 2, 3).as<int>();
    std::cout << "The result is: " << result << std::endl;
    return 0;
}

Status

All planned 1.0.0 features are done and tested; the current state is production-ready.

Who uses rpclib?

This list is updated as I learn about more people using the library; let me know if you don't want your project listed here.

Thanks

rpclib builds on the efforts of fantastic C++ projects. In no particular order:

Shoutouts to

rpclib's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rpclib's Issues

Function overloads

Functions with different signatures but the same name should be possible to bind.

Investigate custom msgpack implementation

I'm not very fond of msgpack's API and its "zone" thingy (which is a leaked implementation detail). If feasable, I would prefer to replace the official implementation with a custom one (probably dropping features we don't need, too).

Move Travis to container-based build

Now that we don't really need sudo for the build (apart from installing a newer clang, which is probably available via the APT addon), we should move to a container-based builder because it is faster.

C++03 support

This is a lot harder than porting back to C++11, but it should be feasible eventually. I would like to steer clear of code generation outside the preprocessor.

Provide a way to dynamically scale the number of worker threads to load

Currently it's only possible to set the number of worker threads when starting the server and then it is set in stone. This PR concerns two features (might need to break it up later):

  • Allow adding and removing workers dynamically (maybe even from handlers)
  • Allow setting a "strategy" that receives various information from the server (i.e. gets notified of calls, sizes of I/O etc.), can store state and can tell the server to spawn or terminate worker threads.

Create benchmarks

Microbenchmarks should be ran on all build just like unit tests. This allows seeing if a commit decreases performance considerably.

Separate transport layer from server

It should be possible to add a different transport layer without code duplication in the server. libuv provides pipes and UDP in addition to TCP.

Add low-level dispatching interface

Systems that already have dynamic type information (e.g. via Reflex or various other reflection solutions) can dispatch calls by implementing a single handler - this requires exposing the call as msgpack object, or maybe just the name of the function to call and a msgpack array as the parameters.

Proper reporting of mismatched argument count

Currently this either results in a bad_cast (if fewer arguments are passed) or just silently dropping the extra if more provided.
If #19 is implemented in terms of storing the arity of the bound functions, that information can be used to easily handle this.

Fix exception in MSVC builds

It looks like MSVC breaks some of the unit tests after recent commits. I can't see what is wrong with the code, so I'm installing windows and visual studio in a VM to check.

Implement client

A client in the vein of

callme::client client("127.0.0.1", 8080);
client.call("foo", 42); // calls foo(42) on the server

Remove libuv from public headers

Since callme ships its own libuv, there should not be any traces of uv types or includes in public headers (even transitively) because users might want to use their own libuvs versions.

Support exceptions in responses

Support should be optional, and there should be policies for:

  1. Catching the exception and transforming it to response, but don't rethrow
  2. Catching the exception and transforming it to response, and throw on the server, too.
  3. Don't transform but throw.

C++11 support

The initial implementation uses very few C++14 features, so it makes sense to try and broaden the compiler support. C++11 is pretty well-supported today.

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.