Git Product home page Git Product logo

redilon's Introduction

Redilón

Redilón is an ultralightweight, simple, fast and opinionated c library for sockets communication that features:

  • An intuitive api
  • A standard packet serialization protocol
  • Two server mechanisms: async non-blocking io and on-demand
  • Robust error handling
  • No memory leaks

Installation

The installation is simple, just run:

  • make
  • sudo make install

Then you'd just include the library like so

#include "redilon.h"

If you want to uninstall the lib run sudo make uninstall && make clean

Basic Usage

See here for more detailed examples.

Create a server:

int main()
{
    int server_fd = redilon_createTcpServer(PORT, QUEUE_SIZE);
    if (server_fd == -1)
    {
        printf("err while creating server: [%s]\n", strerror(errno));
        return -1;
    }
    printf("Server started listening in port %s\n", PORT);

    int epoll_fd;

    // server conf
    redilon_AsyncServerConf conf;
    conf.server_fd = server_fd;
    conf.epoll_fd = &epoll_fd;
    conf.max_clients = MAX_CLIENTS;
    conf.handlersArgs = NULL;
    conf.requestHandler = handleRequest;
    conf.onConnectionClosed = onConnectionClosed;
    conf.onNewConnection = NULL;

    int status = redilon_acceptConnectionsAsync(&conf);

    if (status == -1)
    {
        printf("the server has quit unexpectedly: %s", strerror(errno));
        return 1;
    }

    // should never reach this point
    return 0;
}

Create a client:

int main() {
    int server_fd = redilon_connectToTcpServer(HOST, PORT);
    if (server_fd == -1)
    {
        printf("err while connecting to server: [%s]\n", strerror(errno));
        return NULL;
    }
    redilon_Packet *packet = redilon_createPacket(GET_RESOURCES);
    // we pass the resources as an argument to the handle response
    int res = redilon_sendToServer(server_fd, packet, handleResponse, resources);
}

redilon's People

Contributors

marcosnicolau avatar

Watchers

 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.