Coder Social home page Coder Social logo

yangfei812 / libreactor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fredrikwidlund/libreactor

0.0 2.0 0.0 363 KB

Extendable event driven high performance C-abstractions

License: MIT License

C 95.55% Shell 0.53% Makefile 3.30% M4 0.21% Dockerfile 0.41%

libreactor's Introduction

libreactor v1.0.0

https://travis-ci.org/fredrikwidlund/libreactor.svg?branch=master https://coveralls.io/repos/github/fredrikwidlund/libreactor/badge.svg?branch=master
  • is a modular event driven application framework written in C
  • is an extendable generic framework that can be used for web applications, and many other things
  • comes with a very low overhead
  • is fast (pretty much as fast as it gets)
  • has been production stable for several years serving tens of millions of requests per day
  • has high level abstractions like reactor_server, CouchDB integration and worker pools

Building

The framework depends on libdynamic and libjansson so please install these first.

apt-get install -y build-essential libjansson-dev wget
wget https://github.com/fredrikwidlund/libdynamic/releases/download/v1.3.0/libdynamic-1.3.0.tar.gz
tar fvxz libdynamic-1.3.0.tar.gz
(cd libdynamic-1.3.0; ./configure --prefix=/usr AR=gcc-ar NM=gcc-nm RANLIB=gcc-ranlib; make install)
wget https://github.com/fredrikwidlund/libreactor/releases/download/v1.0.0/libreactor-1.0.0.tar.gz
tar fvxz libreactor-1.0.0.tar.gz
(cd libreactor-1.0.0; ./configure --prefix=/usr AR=gcc-ar NM=gcc-nm RANLIB=gcc-ranlib; make install)

Examples

Hello world web server

$ cat example/hello.c
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <dynamic.h>
#include <reactor.h>

static reactor_status hello(reactor_event *event)
{
  reactor_server_session *session = (reactor_server_session *) event->data;
  reactor_server_ok(session, reactor_vector_string("text/plain"), reactor_vector_string("Hello, World!"));
  return REACTOR_OK;
}

int main()
{
  reactor_server server;
  reactor_construct();
  reactor_server_construct(&server, NULL, NULL);
  reactor_server_route(&server, hello, NULL);
  (void) reactor_server_open(&server, "0.0.0.0", "8080");
  reactor_run();
  reactor_destruct();
}
$ gcc -Wall -Wpedantic -std=c11 -O2 -o hello hello.c -lreactor -ldynamic -pthread -flto

Try it out

The following will build a portable static binary example/hello (~90kB) for the above example code

wget https://github.com/fredrikwidlund/libreactor/releases/download/v1.0.0/libreactor-1.0.0.tar.gz
tar fvxz libreactor-1.0.0.tar.gz
cd libreactor-1.0.0
./configure --prefix=/usr AR=gcc-ar NM=gcc-nm RANLIB=gcc-ranlib
make hello

Run it

./example/hello &
curl localhost:8080

libreactor's People

Contributors

fredrikwidlund avatar

Watchers

James Cloos avatar  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.