socksvc & scgisvc: make them async

Instead of socksvc being a blocking function call, make it return a "handle"
that can be used later to stop the thread and close sockets.

Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
socksvc: rename callback struct

Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
sock: add connect_addr that takes the destination address directly

Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
sock: add xsockaddr_{get,set}_inet_port helpers

Getting and setting port numbers for AF_INET and AF_INET6 is anonying, so
this code hides the details.

Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
sock: return the correct errno on connection error

close(2) will clobber errno, so we need to stash it in a temporary variable.

Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
sock: avoid NULL pointer deref in xsockaddr_ntop

If we get a NULL address, return NULL.

Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
io: document the return value of x{read,write}_partial better

It wasn't clear what they return on success.

Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
sock: make xsockaddr_{cmp,copy} args const

This makes the functions useful more often without ugly casts.

Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
cmake: install jeffpc/timer.h

Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
timer: implement one-shot and periodic timers

There are times when we want to defer work to some time in the future.  This
commit introduces two new APIs - timer API for a one-shot timer which
invokes the callback at the specified time and a periodic API which invokes
the callback at the specified period.

Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
CONTRIBUTING: add info about how to contribute

For the time being, ask for patches to be sent to me directly.

Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
io: add partial read xread/xpread variants

Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
Added signature for changeset ee2327236830

Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
Added tag v0.22-rc2 for changeset 136b22000744

Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
cmake: remove version info from CMakeLists.txt

The version info is always obtained from hg repo history or from
.hg_archival.txt files generated during 'hg archive'.

As a result, new releases will not have "version X.Y" commits anymore, but
they will instead have tag & signature commits.

Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
cmake: rework version & hg commit getting

hg archive generated tarballs include a .hg_archival.txt file which includes
the commit hash, latest tag, and distance from latest tag.  These values can
be combined to create a string much like the template-based version string.

Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
thread: use pthread_cleanup_{push,pop}

Each xthr_create wraps the passed in user function in hopes of executing
code after the function returns to clean up some libjeffpc-internal
thread-local state.  This needs to happen even if the thread called
pthread_exit.

The pthread_cleanup_{push,pop} functions are the POSIX-provided way to run
such cleanup code.

Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
cmake: bump the minimum required version to 3.12

Even Debian old-old-stable (buster) shipped 3.13.

This is needed because modern cmake (3.28) warns about specifying too old of a
minimum required version:

  CMake Deprecation Warning at .../CMakeLists.txt:23 (cmake_minimum_required):
    Compatibility with CMake < 3.5 will be removed from a future version of
    CMake.

Instead of bumping the version to 3.11 (the minimum), this change bumps it
to 3.12 to make it past CMake policy CMP0075 change.  The new behavior
(respect CMAKE_REQUIRED_LIBRARIES in check_include_file) is saner, and so
instead of explicitly opting for it in 3.11 we get it implicitly in 3.12.
For completeness, here's the warning:

  CMake Warning (dev) at /usr/local/share/cmake-3.23/Modules/CheckIncludeFile.cmake:82 (message):
    Policy CMP0075 is not set: Include file check macros honor
    CMAKE_REQUIRED_LIBRARIES.  Run "cmake --help-policy CMP0075" for policy
    details.  Use the cmake_policy command to set the policy and suppress this
    warning.

    CMAKE_REQUIRED_LIBRARIES is set to:

      pthread

    For compatibility with CMake 3.11 and below this check is ignoring it.
  Call Stack (most recent call first):
    /usr/local/share/cmake-3.23/Modules/CheckTypeSize.cmake:256 (check_include_file)
    cmake/config-datamodel.cmake:25 (check_type_size)
    cmake/config.cmake:36 (include)
    CMakeLists.txt:54 (include)

Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
tests: ignore the generated str2float test binary

Should have been done by the commit that introduced the test.

Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
cmake: search for xdr functions in tirpc as well

At some point in the relatively recent past, rpc/rpc.h apparently got moved
from glibc to libtirpc.

Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
Next