Giter Site home page Giter Site logo

tau's Introduction

tau is a C++ asynchronous IO library designed to be fast, minimal and to allow producing beautiful C++ code that does complex things without complexity of low-level system calls.

it is not using any external libraries, is multithreaded, has functions for asynchronous file, network and process IO. to be as efficient as possible it has memory management with reference counting and minimalistic replacements for std::string, std::list and std::map

working under OS X, linux support, extensive testing and documentation is needed.

Building

make builds the library (edit config.mk to select between static and shared builds)

make test runs test cases

Usage

Consider the following code that creates TCP echo server on port 10000 (compile with -I../include/tau -std=c++11 or cd examples && make):

	#include "tau.h"

	using namespace tau;    

	int main( )
	{
	    struct Result: io::Result
	    {
	            virtual void event( ui event, ev::Request& request )
	            {                
	                auto& net = dynamic_cast< io::Net& >( request.parent() );
            
	                switch ( event )
	                {
	                    case io::Net::Listen:
	                        printf( "listening on port %u \n", net.port() );
	                        break;
                    
	                    case io::Net::Accept:
	                    {
	                        auto address = ( fs::Link::Address* ) request.custom();
	                        printf( "accepted connection from %s \n", address->tostring().c() );
	                    }    
                
	                    case io::Net::Read:
	                        net.write( request.data() );
	                        break;
                    
	                    case io::Net::Close:
	                        printf( "connection closed \n");
				  net.deref();	 
	                        break;    
                    
	                    case io::Net::Error:
	                    case io::Event::Error:
	                        printf( "error: %s \n", request.error()->message.c() );
	                        assert( false );
	                        break;
	                }
	            }
        
	            virtual void destroy()
	            {
	                mem::mem().detype< Result >( this );
	            }
        
	            virtual ~Result()
	            {
            
	            }
	        };

   
	        tau::start( [ & ] ( )
	        {
	            auto result = mem::mem().type< Result >();
        
	            io::net( *result, {{ options::Port, 10000 }, { options::Server, true } } );
	            result->deref();
	        } );

	        return 0;
	}

tau's People

Contributors

sarquaz 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.