Set options on new sockets in systematic manner

This patch consolidates the up-to-now scattered code that
sets different options on newly created sockets.

There are open_socket and open_tcp_socket functions that
do the tuning automatically.

In case the socket is not created but got from elsewhere
(such as accept() call) there are tune_socket and tune_tcp_socket
functions that will do the tuning.

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
Checking for correct timeout in the test suite improved

This patch introduces 1/2 second tolerance for the timeouts in the tests.
This will hopefully make tests not fail even on slow or heavily loaded
machines.

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
If available, use MSG_NOSIGNAL for send()

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
Check for SO_NOSIGPIPE availability instead of OS name

* src/stream_engine.cpp (stream_engine_t::stream_engine_t):
Use
    #ifdef SO_NOSIGPIPE
instead of
    #if defined XS_HAVE_OSX || defined XS_HAVE_FREEBSD
Define _GNU_SOURCE in addition to the __BSD_VISIBLE on freebsd-like hosts

Define _GNU_SOURCE in addition to the __BSD_VISIBLE on the freebsd-like
hosts.  It made in hope to cover cases and obtain the full power of
underlying kernel on "hybrid" systems like Debian GNU/kFreeBSD, when
GLibc (or derived) library lives on top of FreeBSD kernel.

On the "real" FreeBSD it only enables getline(3), and therefore, should
not hurt.

* configure.ac: Define _GNU_SOURCE in addition to the __BSD_VISIBLE for
cover GLibc (or derived) on top of FreeBSD kernel cases, as it is in
Debian GNU/kFreeBSD case.
Separate subscription forwarding from SUB-side filtering

- subscription forwarding is handled by XSUB socket
- filtering is handled by SUB sockets
- subscriptions are decoupled from filter engines
- filter doesn't have to be able to enumarate the subscriptions
  (no sf_enumerate function)

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
Report EMFILE/ENFILE from xs_socket()

This patch propoagates the error from signaler and mailbox
initialisation up the stack.

To achieve this signaler and mailbox classes were re-written
is C-like syntax.

Finally, shutdown_stress test now ignores EMFILE/ENFILE errors.
Thus, the tests should pass even on OSX which sets the max
number of file descriptors pretty low by default.

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
Minor improvement to error reporting

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
Filters can transform user subscriptions to wire subscription

Till now the subscription, as specified by the user, was send
upstream.

This patch allows SUB-side filter to transform the user subscription
into wire subscription. For example, only a has can be sent upstream
instead of a perfect subscription.

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
thread_t rewritten in C style

thread_t is one of the classes where C++ syntax creates more
problems then it solves. This patch converts it into simple
C-style pseudo-class.

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
Merge branch 'master' of https://github.com/crossroads-io/libxs
Merge branch 'master' into dtrace
Fixed a warning in the timeo test

Fixed a couple of mixed signed/unsigned comparison which in conjunction
with -Werror prevented compilation of the test.

Signed-off-by: Gabriele Svelto <gabriele.svelto@gmail.com>
Merge branch 'master' of https://github.com/crossroads-io/libxs
Merge branch 'master' into dtrace
Introduce support for tracing inter-object commands