Rapid Development C utility library
C C++ Other
Switch branches/tags
Nothing to show
Clone or download
Permalink
Failed to load latest commit information.
debian First stab at debian packaging. Mar 1, 2013
examples Improved usage of .PHONY-target as per make manual Apr 28, 2014
tests Improved usage of .PHONY-target as per make manual Apr 28, 2014
.dir-locals.el Initial commit Apr 10, 2012
.gitignore gitignore update Sep 6, 2012
LICENSE Updated Copyright year Mar 1, 2013
LICENSE.pycrc Added pycrc LICENSE file May 18, 2012
Makefile Improved usage of .PHONY-target as per make manual Apr 28, 2014
README.markdown Removed Apache Kafka support. It is available in librdkafka. Apr 30, 2013
rd.c Updated Copyright year Mar 1, 2013
rd.h Updated Copyright year Mar 1, 2013
rdaddr.c Updated Copyright year Mar 1, 2013
rdaddr.h Added RD_SOCKADDR_INX_CMP() Jun 18, 2013
rdalert.c alert callback takes a va_list, not a var-arg list Jun 23, 2014
rdalert.h alert callback takes a va_list, not a var-arg list Jun 23, 2014
rdavg.c Added roll_callback for rd_avg. Will be called when an average period… May 14, 2013
rdavg.h Added roll_callback for rd_avg. Will be called when an average period… May 14, 2013
rdavl.c Updated Copyright year Mar 1, 2013
rdavl.h Clear avl_node memory before insert Nov 12, 2013
rdbits.c Updated Copyright year Mar 1, 2013
rdbits.h Cosmetics changes Dec 12, 2013
rdbuf.c Change TAILQ_FOREACH_SAFE parameters to bsd order May 24, 2017
rdbuf.h Updated Copyright year Mar 1, 2013
rdcrc32.c Added CRC32 functions (generated by pycrc) May 14, 2012
rdcrc32.h Added CRC32 functions (generated by pycrc) May 14, 2012
rdencoding.c rd_hex2bin: ignore \n and \r in hex strings May 6, 2013
rdencoding.h Updated Copyright year Mar 1, 2013
rdenum2str.pl Updated Copyright year Mar 1, 2013
rdevent.c Updated Copyright year Mar 1, 2013
rdevent.h Updated Copyright year Mar 1, 2013
rdfile.c Fixed fd leak in rd_file_read() Apr 23, 2013
rdfile.h Updated Copyright year Mar 1, 2013
rdfloat.h Updated Copyright year Mar 1, 2013
rdgz.c Updated Copyright year Mar 1, 2013
rdgz.h Updated Copyright year Mar 1, 2013
rdio.c Updated Copyright year Mar 1, 2013
rdio.h Added license headers where needed. Apr 22, 2013
rdiothread.c Compile on gcc 4.1 (!) Jan 16, 2014
rdiothread.h Added license headers where needed. Apr 22, 2013
rdlog.c fix strict-overflow error Sep 20, 2016
rdlog.h FIX: bad name in rd_log_set_severity May 15, 2014
rdlru.c Added rd_lru_cnt() and fixed lru counter (thanks to Eugenio for repor… Sep 17, 2013
rdlru.h rdlru.h needs to include rdthread.h, because rd_mutex_t used Nov 28, 2013
rdmem.c Updated Copyright year Mar 1, 2013
rdmem.h FIX: added rd_memctx_strdup RD_UNUSED, and cosmetics changes Dec 12, 2013
rdopt.c Added rd_opt_description_set(): allows giving extra information along… May 14, 2013
rdopt.h Added rd_opt_description_set(): allows giving extra information along… May 14, 2013
rdqueue.c Free eventq and thread handle on thread exit. Mar 6, 2013
rdqueue.h Suppressed not used warning. Aug 12, 2013
rdrand.c Updated Copyright year Mar 1, 2013
rdrand.h Updated Copyright year Mar 1, 2013
rdsignal.h Updated Copyright year Mar 1, 2013
rdstring.c Updated Copyright year Mar 1, 2013
rdstring.h Updated Copyright year Mar 1, 2013
rdsysqueue.h Change TAILQ_FOREACH_SAFE parameters to bsd order May 24, 2017
rdthread.c Force rd_thread_poll() exit of thread is exiting, even if there are p… Jul 11, 2013
rdthread.h Let rd_thread_create() assign the thread variable to avoid race condi… May 6, 2013
rdtime.h Updated Copyright year Mar 1, 2013
rdtimer.c Revert "Fixed rd_alert() call to be va-arg safe" Jun 23, 2014
rdtimer.h Fixed race condition in timer code. Apr 22, 2013
rdtypes.h Updated Copyright year Mar 1, 2013
rdunits.c Updated Copyright year Mar 1, 2013
rdunits.h Updated Copyright year Mar 1, 2013

README.markdown

librd - Rapid Development C library

Copyright (c) 2012-2013, Magnus Edenhill, et.al.

https://github.com/edenhill/librd

librd aims to provide the commonly needed helpers, sub systems, snippets and misc. functionality that lacks from the standard C libraries, allowing for rapid development of new programs and non-intrusive extension of existing applications.

librd is non-intrusive in the sense that single specific functionality from librd can be used by the application without having to use or initialize other parts of the library. In its most simple form you add -lrd -lz -lrt to your linking step and include the proper rd<FUNC>.h include file for your desired functionality.

librd is licensed under the 2-clause BSD license.

librd provides, on a higher level:

  • proper thread support throughout the library
  • consistent, natural and non-bloated APIs and interfaces
  • scalability and performance
  • proper documentation (some time in the future)
  • suitable for embedded systems, large-scale backend systems, GUI applications, etc.

Functionality

Non-exhaustive list of current librd functionality:

  • rdqueue.h: Thread-safe FIFO queues (nice for worker queues).
  • rdthread.h: Thread management abstraction.
  • rdmem.h: Memory contexts for contextual malloc's allowing memory usage supervision and free-all-context-memory-at-once.
  • rdmem.h: Efficient memory and allocation helpers: `rd_calloc_
  • rdsysqueue.h: Improved sys/queue.h
  • rdopt.h: Short (-c) and long (--config) command line argument option parsing with input validation and automatic variable assignments.
  • rdfloat.h: Float comparison helpers.
  • rdaddr.h: AF_INET and AF_INET6 agnostification.
  • rdbuf.h: Generic buffers with (de)serializer/writer/reader callbacks.
  • rdstring.h: String helpers: rd_strnchrs().
  • rd.h: Convenience macros and porting alleviation: RD_CAP*(), RD_ARRAY_SIZE(), RD_ARRAY_ELEM(), RD_MIN(), RD_MAX().
  • rdavl.h: Thread-safe AVL trees.
  • rdio.h: Socket/fd IO abstraction and helpers.
  • rdfile.h: File/filesystem access helpers.
  • rdencoding.h: Various encoder and decoder helpers (varint).

Usage

Requirements

The GNU toolchain
pthreads
zlib

Instructions

Building

  make all
  make install
  # or to install in another location than /usr/local:
  DESTDIR=/my/prefix make install

Rigid building

The above procedure continues on test failures, but that might not be desirable, so here's how to do make sure the tests pass before installing.

  make libs test install

Usage in code

  #include <librd/rd.h>
  #include <librd/rdFUNCTIONALITY.h>

  ...
  rd_init();
  ...

  rd_....();

Link your program with -lrd -lz -lrt.

Documentation

Documentation is still lacking, but each public function and concept is described in its .h header file while internal functions are described in their .c files.

Testing

Regression tests are integrated into the build process. The tests are in the tests/ sub-directory.

Examples

The test programs in the tests/ sub-directory serve as examples, but some more explicit examples will be provided in the examples/ sub-directory.

More documentation and usage examples will come.

Apache Kafka

NOTE: The Kafka implementation has been moved to its own library. See librdkafka.

Public projects using librd

TODO

Scattered lists of things to do:

  • Generic thread-safe linked-lists that does not require a struct field. i.e.: obj->ll = rd_ll_add(mylist, obj);
  • librd should be aware of the number of CPU cores so it can be used to create an appropriate number of workers, if thats what matters. i.e.: rd_workers_create(..., rd_conf_getu32("sys.cpu.cores") * 16);
  • Configuration/.rc file support using the rd_opt_t framework allowing the same configuration token to be specified both as command line argument, CLI command and configuration file directive without any extra development effort.
  • rdmkbuildtree.sh - script to generate makefiles at the start of a project, debian directories, etc.
  • Add anything else that may come in handy for more than one program ever.