Skip to content

C++ asynchronous & simple network framework

License

Unknown, GPL-2.0 licenses found

Licenses found

Unknown
LICENSE
GPL-2.0
COPYING
Notifications You must be signed in to change notification settings

gunoodaddy/coconut

Repository files navigation

Coconut

Coconut is C++ network framework with briefly, clearly, high performance.

  • Using libevent (available for switching another network library)
  • Available cross platform linux, windows (by using libevent)
  • Easy multithread service
  • Tcp Socket
  • Unix Domain Socket(only tcp)
  • Udp Socket
  • Http Client (GET, POST)
  • Simple Http Server
  • Redis Request (optional)
  • JSON Stream Protocol (optional, now unstable)

TODO

  • fix -without-json option in configure.ac
  • fix boost include path

TCP Echo Server Example

total 26 lines. (It's not iocp sample.)

#include "Coconut.h"
using namespace coconut;

class FooSession : public BinaryController {
    virtual void onReceivedData( const void *data, int size ) {
        socket()->write(data, size);
    }
};
class FooServer : public ServerController {
    virtual boost::shared_ptr<ClientController> onAccept( boost::shared_ptr<TcpSocket> socket ) {
        boost::shared_ptr<FooSession> newSession( new FooSession );
        return newSession;
    }
};
int main( int argc, char **argv ) {
    IOServiceContainer container( 16 /* thread count */ );
    container.initialize();
    try {
        boost::shared_ptr<FooServer> fooServer( new FooServer );
        NetworkHelper::listenTcp( &container, 8000, fooServer );
        container.run();
    } catch(Exception &e) {
        // Error
    }
    return 0;
}

TCP Echo Server Performance Result

Environment

Requirement

libevent >= 2.0.15

http:https://libevent.org/

  • If you use Win32 IOCP, you must use this libevent.
  • Original libevent >= 2.0.15 has a bug in evutil_tv_to_msec function. (need to add tv pointer null check code)
  • And we've added free callback feature for struct evhttp_request to know which evhttp_request pointer will be freed. It needs if you should store http request and then later send responses. (like 'Commet'). You can see our fixed codes by finding gunoodaddy comment in this libevent sources.
  • By running configure, it will check our free callback feature exists in your own libevent and then mark HAVE_LIBEVENT_GUNOODADDY_FIX in config.h.

boost >= 1.33.0

boost 1.48.0 download

  • You must build boost library (run b2), we need boost stage library for using boost::thread

hiredis (option : --without-redis)

https://github.com/antirez/hiredis

  • On Win32, you must use this hiredis instead of orginal hiredis so that the build is successful.
  • If you do not want to use redis, run configure --without-redis.

libjson 7.4.1 (option : --without-json)

libjson 7.4.1 download

  • In order to build successful, you must use 3rdParty/src/libjson instead upper link's libjson.
  • We modified JSONStream class to parse correctly. (7.4.1 libjson has a few bug in JSONStream)
  • You can find 'gunoodaddy' comment in 3rdParty/src/libjson modified codes.
  • And if you use linux 64bit os, must edit <lib_json_root>/makefile to add -fPIC to cxxflags_default.
  • If you do not want to use json feature, run configure --without-json.

Build / Installation on linux

export BOOST_ROOT=<BOOST ROOT DIR>
export LD_LIBRARY_PATH=<BOOST STAGE LIB DIR>:$LD_LIBRARY_PATH

configure
(configure --with-boost-libdir={BOOST_HOME}/stage/lib)
make
cd test
unittest

Build / Installation on windows

visual studio >= 2008 needs.

open Win32/Coconut.sln
build

TODO before linux configuration

autoheader
(optional) cp  /usr/share/libtool/config/ltmain.sh .
automake -a --copy
autoconf

DO NOT run aclocal
libtool 2.4.2, automake 1.11, autoconf 2.68 need

http:https://ftp.gnu.org/gnu/autoconf/autoconf-2.68.tar.gz

http:https://ftp.jaist.ac.jp/pub/GNU/libtool/libtool-2.4.2.tar.gz

http:https://ftp.gnu.org/gnu/automake/automake-1.11.tar.gz

TODO before windows configuration

copy libevent source to 3rdParty/src/libevent
copy hiredis source to 3rdParty/src/hiredis

About

C++ asynchronous & simple network framework

Resources

License

Unknown, GPL-2.0 licenses found

Licenses found

Unknown
LICENSE
GPL-2.0
COPYING

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published