Coder Social home page Coder Social logo

ermiry / cerver Goto Github PK

View Code? Open in Web Editor NEW
18.0 18.0 11.0 5.2 MB

Cerver is a development framework, created by Ermiry, designed to provide you with the necessary tools for creating fast and reliable multipurpose servers written in C.

Home Page: https://cerver.ermiry.com

C 98.15% Makefile 1.30% Shell 0.44% Dockerfile 0.07% Ruby 0.04%
c server

cerver's Introduction

Hello there! ๐Ÿ‘‹, I am Erick Salas

Never stop creating

  • ๐Ÿ”ญ Iโ€™m currently working on Cerver Framework

  • ๐ŸŒฑ Iโ€™m currently learning Custom implementations of ML and AI algorithms in C/C++ using cuda

  • ๐Ÿ’ฌ Ask me about Linux, C/C++, Cloud Services, ML, Flutter, React, Dev-Ops

  • ๐Ÿ“ซ How to reach me [email protected]

cerver's People

Contributors

ermiry avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

cerver's Issues

Enhance client example

  • Better code structure
  • Showcase the creation of multiple client using different methods

Connection gets stuck when handling a request as a web cerver using thpool

We can generate the response correctly, but when calling the following methods to end the connection, we get stuck somewhere

// after the performed action, close the client socket
Client *client = client_get_by_sock_fd (receive->cerver, receive->socket->sock_fd);
// client_drop (receive->cerver, client);
client_remove_connection_by_sock_fd (receive->cerver, 
	client, receive->socket->sock_fd);

Check client_unregister_from_cerver ()

Specially when called from

client_remove_connection_by_sock_fd ()
client_drop ()
client_unregister_from_cerver ()

  • Room for optimization - check connections size before performing operations
  • When are we removing client from htab

Idea

Maybe when removing client from htba, or not removing it is causing segfault
At the time of this writing, htba is not thread safe

Possible double lock in cerver_poll_register_connection ()

Possible double lock of cerver->poll_lock when calling cerver_poll_register_connection () and we need to realloc the poll array as it might be full!

Possible solution

Split in two methods, one is the public method which will manage the flow (and will lock), and the second will perform the actual insertion in the array (and will NO lock).

Add option to handle connections in dedicated threads

Right now we only use poll () to select which socket to call recv () on, and then we handle the buffer using the thpool or in the same thread. We need to offer an option to create a dedicated thread for each connection.

Also create benchmarks to test which is the best option in each case.

Web socket implementation

Implement a fully fetch web socket module

  • Set route modifier to enable web sockets connections
  • Correctly handle http request headers to enable web sockets
  • Disable connection closing after the first http request has finished
  • Correctly handle data frames (receive & send)
  • Implement callback methods to be called on various web socket events (open, close, message, etc)

Refactor admin cerver flow and methods

Refactor how admins work in cerver to increase their performance and their usage

  • Remove dedicated socket to listen for new admin connections (accept & receive)
  • Remove dedicated receive methods, as they are duplicates of the ones found the main handler
  • Remove existing credentials logic and replace it with the ability to take a user defined method instead
  • Remove dedicated auth methods, as they are copies of the main auth methods and use them instead
  • Refactor admin handlers to use latest Handler structure

Ability to display & interact with a menu to check cerver stats

Add the ability to interact with a menu (inspired by Flutter) to directly check on cerver status & display information about current cerver structures & clients. This will be useful to help in the debugging process & will complement cerver-connect which requires to setup dedicated admins.

Add support for udp connections

We have some methods already in place to handle sending and receiving packets using the udp protocol, however, it has never been implemented.

Refactor client handler methods

Refactor client handler methods to correct use latest code from main cerver handler. Also replace handler Action to the new Handler structure.

  • Refactor client structure
  • Refactor client handler methods
  • Correctly init handler threads when client starts, if needed
  • End client handlers in client teardown

Segfault on client disconnect

When a client sends use a CLIENT_CLOSE_CONNECTION packet, we get a segfault some times.

Tested with 16 clients, all connect and send test messages as expected, however, almost when always, when 14/16 client have disconnected, when disconnecting 15th we get a segfault in the server.

Server configuration:
cerver_set_receive_buffer_size (my_cerver, 16384);
cerver_set_thpool_n_threads (my_cerver, 4);

image

Ideas

Relate to use #26 for a possible solution

Subroutine to check for inactive clients

  • Add the ability to set cerver's option to check for inactive clients
  • Refactor client structure to keep track of the last time it had activity
  • Create a dedicated thread for client inactivity checking
  • Check for when a client was last active (made a request) and if it was some time ago, drop the client.
  • Every time the cerver receives a packet from a client (connection) or a packet is sent to him, the inactivity time must be updated
  • We need a mutex inside client structure to correctly handle dropping clients from multiple threads

Refactor / Re-implement avl tree

After testing, we found that at least two segfaults were caused directly by the avl data structure:

  • The first one related to issue #40 was solved by refactoring avl_remove_node_r (). This was found to be in every version at least from 1.3.1 but probably even before, not real way to tell.

  • The second one related to issue #27 solved by adding additional checks in methods for NULL values.

This is specially concerning as we need to do more testing to check if we are indeed getting the correct behavior of an avl after the modifications. More testing will be done, but a good idea will be to completely re-implement the avl collection.

Refactor client start methods

  • Create a new client_start () that should be used after client_connect ()
  • Refactor existing start method into client_connect_and_start ()

Received NULL ptr when attempting to remove a client from cerver's client tree

This error only happens only when removing the first client that connected to the cerver when there ate least two clients connected. If only one client is connected or we remove the second or any other client before the first one, it does not happens.

Tested in cerver versions as low as 1.3.1 and we get the same result.

Add client events

Add the events from cerver-client into cerver's client. This events are mostly when connecting one cerver to another or to better manage client connections / requests to another type of server.

Problems in client_remove_connection_by_sock_fd ()

  • In the default case of client_remove_connection_by_sock_fd () we are not correctly removing the connection from the client
  • Connections should be closed & removed from client in one method, and in another one, they should be unregistered from the cerver
  • Refactor connection_remove () with a similar logic to the one implemented in admin cerver

Use latest handler structure in single handler server

Single handler server (original) is not using the latest handler structure. This will allow use to also create dedicated handler data when the main handler starts. We need to change app_packet, app_error_packet and custom_packet handler from being Action to Handler

Create an admin exmaple

Use this example to show case how admins can connect to the cerver and how to enable them in the cerver. This will also be useful for testing admin methods.

Enable or disable packet checking

We have the methods in place to correctly check if a packet is valid or not but have been disabled. Add the ability to select to perform packet checking (version, protocol id, etc) or not.

Remove compress clients (poll fds array) option

Remove the option to compress clients (poll fds array) as it is no longer used

  • Remove cerver_poll_compress_clients ()
  • Remove cerver_on_hold_poll_compress ()
  • Remove compress option from cerver structure
  • Remove compress checks from poll methods

Inconsistent receives when using thpool in cerver_poll ()

When using only a single thread for handling messages from already connected clients, we get the expected result for one or more clients connected at once.

However, when we choose to handle using the thpool, we get inconsistent received and handler methods. And it appears that the socket or therad just hang up and stop sending and / or receiving messages.

Client sending test packets to cerver
image

We also get a segfault when exiting the cerver.
image

Possible Cause

As we don't have the array of fds in cerver as a thread safe structure, when calling cerver_receive_handle_failed () when a client disconnects, may cause the segfault as we are still trying to access it from the cerver_poll () at the same time. This, however, will not explain the inconsistent handles.

Better cerver to cerver connections

Correctly handle:

  • Cerver requires authentication - cerver_check_info ()
  • Cerver teardown - disconnect event - client_cerver_packet_handler ()

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.