libporty - the net_async package

This high level package provides different functionality behind emulated networking (sockets). This allows the user application to implement a simple, common main loop around P_poll() that handles all different tasks the same, unified socket-operation way. This is achieved by running some tasks in the background, in parallel to the caller application. These tasks are always connected to the application using local (pollable) non-blocking sockets.

On UNIX systems, libporty implementation uses fork() for running tasks in the background. Most systems implement copy-on-write for memory pages thus the method is not expensive. On win32, very simple threading is used.

libporty/net_async/abgproc.h

Run background processes. Main communication channel is the standard input/output of the process, which is bound to the main socket. A second, optional control socket may be created to monitor process startup/shutdown.
call level summary
P_net_async_bgproc high run a background process with stdio hooked to a socket

libporty/net_async/adns.h

Run a background task for resolving (hostname to IP or IP to hostname). Requests and answers are done through the socket created. The background task runs blocking DNS lookups sequentially. It is possible to run multiple instances for parallel lookups, but load balancing needs to be done on the caller's side.

The caller should use async dns to convert any hostname to ip address. Once only ip addresses are fed into low level net calls, it is guaranteed that no blocking will happen in those calls for DNS lookups.
call level summary
P_net_async_dns high run a background DNS resolver for asynchronous lookups

libporty/net_async/astdio.h

Non-blocking stdio. On some systems (win32), it is impossible to set stdin and stdout to fully nonblocking. On those systems the only way is to run background tasks that handles stdio in blocking manner while working from/to a non-blocking socket. The user application is using the other end of this non-blocking socket.

On systems that support non-blocking stdio (UNIX), no background tasks or extra sockets are created, but fd of stdio is set to non-blocking is returned, avoiding any overhead.
call level summary
P_net_async_stdio high return a non-blocking socket for stdio