overview - OkCupid/sfslite GitHub Wiki

sfslite Source Tree Overview

sfslite has many useful components for simplifying the development of event-driven network programs in C++.

sfslite and the SFS libraries are also known as libasync, which is somewhat of a misnomer, since the sfslite/SFS suite contain libasync in addition to other libraries.

  • Main event loop (amain and acheck) and mechanisms for registering callbacks to handle:
    • file descriptor read/write-ability using fdcb,
    • periodic actions using delaycb,
    • unix signals using sigcb.
  • Reference counted data structures (refcnt.h)
  • Closure-like syntax for generating callbacks and maintaining state across actions (wrap in callback.h)
  • Reference counted string objects (str.h): immutable strings, string buffers, mutable strings and mutable strings that are explicitly wiped after use.
  • suio in C++, a wrapper to simplify using iovec to efficiently buffering input and output.
  • aios for writing line-oriented network servers/clients.
  • Data structures:
    • generic linked list logic (list.h)
    • generic hash table logic: ihash for when you provide struct that knows it is in a hash table, qhash for generic structs into hash tables, bhash for when you just want to keep track of whether or not a key is present (ihash.h and qhash.h). A short tutorial on qhash is available here.
    • dynamic arrays (vec.h)
    • red black trees (itree.h)
  • Functions/classes for common operations:
    • Allocating sockets (inetsocket, make_async, unixsocket)
    • asynchronous DNS lookups.
    • asynchronous TCP connections (tcpconnect)
    • Daemonizing servers
    • Logging, error output and traces (err.h)
    • Parsing configuration files (parseopt.h)
    • Regular expressions (via the pcre library)

Sfslite makes extensive use of C++ templates to provide flexibility without sacrificing type safety. sfslite does not use floating point operations. sfslite is designed to integrate well with the dmalloc debugging malloc library.

A basic tutorial on using the SFS/sfslite libraries is available from PDOS.

If you have any tips for using libasync, please contribute them!