NMSTL is the Networks, Messaging, Servers, and Threading Library, a portable C++ library for writing, well, networking and messaging components, servers, and threaded applications. In general, the intention is that NMSTL is to "systems stuff" what STL is to algorithms and containers.
NMSTL contains lots of components intended to make it easier to write applications in C++. It's high-performance - as in STL, nearly everything is implemented such that a good compiler will inline and optimize away nearly all the object-oriented overhead.
Here's what's included so far. NMSTL is still just a baby, but it'll be growing up fast over the next few weeks.
run
method is invoked in a separate thread.
NMSTL introduces the locking
construct which makes it easier to write code that automatically releases a lock at the end of a block - no more accidentally forgetting to drop your mutex (an endless source of pain in debugging concurrent apps).
class MyClass { mutex m; int some_function() { locking (m) { if (foo == bar) return 89; else ...; } return 33; } }
ioctl
and fcntl
, sockaddr_in
and sockaddr_un
, gethostbyxxx
, socket
and bind
and friends. Opening a connection, is as easy as in Java (and you get to do things either synchronously or asynchronously).
DEBUG << arg1 << arg2 << ... ; INFO << arg1 << arg2 << ... ; WARN << arg1 << arg2 << ... ; ERROR << arg1 << arg2 << ... ; FATAL << arg1 << arg2 << ... ;Those args are like varargs - you can use, with type safety, anything that will convert to a string:
inet_address addr = ...; INFO << "Accepted connection from " << addr << " in thread " << thread::self();Using one of these macros generates a debugging message containing the file name, line number, and your arguments. The debug level can be individually configured in the environment of the calling process (e.g., your shell) for each source file, so you can turn on debugging only for particular files (XXX: not yet; currently only one debug level). Eventually this facility will be expanded to support customization of format and integrated syslogging.