This is a stream of data arriving in chunks. With a native TCP stack,
it will serve individual buffers as arriving from the network interface and
queued by the TCP stack. With the hosted stack (bsd_data_source_impl),
we unfortunately have to allocate each chunk individually.
Cleanly join the worker thread during termination, to avoid an EBADF when
the signalfd used for communication is destroyed. This lets atexit handlers
run, specifically leak detectors.
Instead of returning a pollable_fd from server_socket::accept(), return
a new abstract class connected_socket, which is able to provide an
input_stream and an output_stream to the caller.
Instead of returning the Unix-tied pollable_fd, return an abstract
server_socket class which is then implement atop pollable_fd, but can
be replaced with a native implementation.
Since they are going to be the abstract interface to both the bsd socket
layer and the native tcp stack, rename them to more generic names -
input_stream and output_stream.
Add a share() method that enables reference counting for the packet and
returns a clone. The packet's deleter will only be invoked after all clones
are destroyed.
This is useful for tcp, which keeps a packet in the unacknowledged transmit
queue while sending it lower down the stack.
Instead of returning a future<packet>, return a future<> (signifying data
is available) and provide a read() method.
This is useful in case the user wants to consume more or less than exactly
one packet.
Rudimentary TCP support (establishes a connection then falls over, lots of
things missing).
In a departure from tradition, we don't have a state enum with all the
traditional LISTENING states etc. Instead we have boolean values
indicating whether an event (like a remote SYN received, or our SYN
acknowledged) has happened. This simplifies things, because in TCP
the sending side and the receiving side are mostly orthogonal, while the
TCP state mixes the two.
TCP is implemented as a template, in order to tune it for the differences
in TCP/IPv4 vs. TCP/IPv6 (mostly address size and pseudo header).