Git Product home page Git Product logo

ykz's Introduction

ykz

MIT licensed

A hackable and scalable request/response TCP server that you can call yours.

Features

  • define 4 hooks and your server is ready for takeoff
  • edge-polled event handling
  • no external dependencies
  • easy to port to other OSes

Example

This is how a basic 'echo' server looks like with ykz:

#include "ykz.hpp"

using namespace ykz;

/* Triggers after host_start() is called and before starting to wait for connections */
void init()
{
}

/* Triggers when some data has been received */
proto_result okay(void *data)
{
    /* Possible return values:
    
    PRS_SWITCH_MODE: switch from receiving mode to sending mode
    PRS_SUGGEST_WAITING: a hint to wait for more data
    PRS_INTERNAL_ERROR: close the connection

    */

    return PRS_SWITCH_MODE;
}

/* Triggers when a client is disconnected from the server */
void goodbye(void *data)
{
}

/* Triggers after host_stop() is called and before it returns */
void cleanup()
{
}

int main(int ac, char *av[])
{
    Host h;
    Protocol echo{
        &init,
        &okay,
        &goodbye,
        &cleanup,
    };
    
    host_start(h, echo, IP_STRING_TO_U32("127.0.0.1"), 8080);
    
    /* ... <do something or wait> ... */
    
    host_stop(h);
    
    return 0;
}

See also

A HTTP/1.1 GET/HEAD-only implementation is provided in protocols/http_mini/. The goal is to support delivering static content and that's it.

I'm planning to add a game implementation with more complex logic. Be back ๐Ÿ”œ

Configuration

File: ykz.config.hpp

Values:

Name Type Value
CLOSE_ON_RESPONSE bool Controls if the connection is closed after the response has been sent
HEADER_LENGTH u32 The length in bytes of the message buffer
DRIVERS_PER_HOST u32 The number of event-loop threads spawned by a single Host
GUESTS_PER_DRIVER u32 The limit of simultaneous connections handled by a single event-loop thread
EVENTS_PER_BATCH u32 The limit of events returned per event-loop
LISTEN_SOCKET_BACKLOG s32 A hint to the listen(2) implementation to limit the number of pending connections on the listening socket

Compilation

TDB

ykz's People

Contributors

spectrevert avatar

Stargazers

 avatar  avatar

Watchers

 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.