GithubHelp home page GithubHelp logo

libog's Introduction

---------------------------------------

libOG is a minimalist C++ network library providing just enough boiler-plate to use and monitor event-based, non-blocking TCP/UDP sockets.

disclaimer
----------
The library is currently in active development. Interfaces and code are not stable and can change drastically.

strictly conventional and simple
--------------------------------
libOG is designed as a weightless object-oriented layer over the Unix socket functions. It can be used for writing simple servers and client or as a base for higher-level asynchronous code.

As such, are avoided most c++ features presenting potential overhead in compilation time, code size or readability. Errors are communicated through return codes and error handling is left to the user.

features
--------
The typical TCP and UDP classes will be provided by libOG, as well as some base classes for extensibility reasons:
	
	<> Socket       implemented, base class for socket objects
	<> TcpStream    implemented, TCP client socket
	<> TcpListener  implemented, TCP listener socket
	<> UdpSocket    implemented, basic UDP socket

+-------------------------------------+
|              ISource                | interface for monitorable source
+-------------------------------------+
|               Socket                | base class for sockets
+-----------+-------------+-----------+
| TcpStream | TcpListener | UdpSocket | specialised classes
+-----------+-------------+-----------+

libOG also has classes aimed at monitoring events:

	<> Poll         implemented (epoll only), used to monitor event sources
	<> Event        implemented, used to manipulate/examine events

+----------------------------------+
|                IPoll             | interface for monitor of event sources
+----------------+-----------------+
|  Poll (epoll)  |  Poll (kqueue)  | specialised implementations
+----------------+-----------------+

non-features
------------
libOG is not:
 * a general event notification library (libev)
 * an asynchronous sockets framework (libuv)
 * a threading library (libpthread)
 * a $h!tfest of template metaprogramming and dependencies (Boost.Asio)

compilation
-----------
Requirements: a c++14 compliant compiler

documentation
-------------
There will be extensive documentation generated from the source files and comments released on 1.0

As of now, the code is mainly self-explainable. Feel free to dive in. 

license
-------
libOG is an open source, libre project licensed under the MIT license.

libog's People

Contributors

spectrevert avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

libog's Issues

TcpListner::accept() performs non-wanted socket intialization

Issue

The TcpListener::accept method uses intl::accept under the hood; which itself calls either accept4 or accept and stores the newly created socket handle inside the referenced new_socket. See:

int intl::accept(SocketHandle socket, SocketHandle &new_socket,

The problem is that this newly created socket handle is used to replace the one from the referenced new_stream from TcpListener::accept using the TcpListener::handle call.

This means that new_stream is initialized, a socket is created, but then is closed and replaced by a new handle. See

int TcpListener::accept(TcpStream& new_stream, SocketAddr& new_address,

See attached strace output. I've lightly commented/modified it.

# start of program - let's say a TCP server
socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, IPPROTO_IP) = 3
epoll_create1(EPOLL_CLOEXEC)            = 4
bind(3, {sa_family=AF_INET, sin_port=htons(6970), sin_addr=inet_addr("127.0.0.1")}, 16) = 0
listen(3, 128)                          = 0
epoll_ctl(4, EPOLL_CTL_ADD, 3, {events=EPOLLIN|EPOLLOUT|EPOLLRDHUP|EPOLLET, data={u32=1, u64=1}}) = 0
epoll_wait(4, [{events=EPOLLIN, data={u32=1, u64=1}}], 1024, -1) = 1
socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, IPPROTO_IP) = 5 # new_stream initialized
accept4(3, NULL, NULL, SOCK_CLOEXEC|SOCK_NONBLOCK) = 6           # and passed to ::accept
close(5)                                = 0       # as the new handle gets assigned the first one is closed

Proposition

Obviously this presents some unwanted overhead and operations.

An optimal solution would be to use a class like expected<T, E> that would make us be able to change the TcpListener::accept call into the following method::

expected<TcpListener, og::net::Error> accept(SocketAddr& new_address, int flags);

Unfortunately the std doesn't have such expected class available yet and I've yet to write the copy operators for all of the classes.

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.