rtl-ais
rtl-ais copied to clipboard
New feature: `-k` flag (keep streaming new data to TCP connections)
This change set adds the -k
flag, which affects the TCP listener. When -k
is given, the TCP socket will continue to publish newly-decoded messages to any connected clients.
I've tried to keep unnecessary diffs to a minimum. Here's a summary of the major parts of the change:
typedef struct t_sockIo {...}
The struct which tracks open TCP clients is extended to add int msgpipe[2]
. These will store two file descriptors, as created by pipe(2)
, for the decoder thread to publish to the connection thread. This pipe is created when a new client connects, and destroyed upon disconnect.
add_nmea_ais_message(..)
When a new message is decoded, and the global _tcp_stream_forever
option is set, this method is extended to publish the message to all connected clients. It does do by write(2)
ing to the msgpipe
fd.
handle_remote_close(..)
This method continues to service remote TCP clients. After publishing buffered messages (existing functionality which is unchanged), it waits on a blocking pselect(2)
loop for one of two things to happen:
- New data is available on the read fd of
msgpipe
. It writes it out to the tcp socket. - New data arrives from the tcp socket. By previous convention, this causes the server to close the socket.
- It's not clear to me if that behavior remains necessary here; i.e., we could ignore reads and let the client close when it wants.
When -k
is not specified, no data is ever published to msgpipe
; so the existing behavior remains intact.
Other/unrelated changes
There are two other commits here which address minor/unrelated things I ran into. It might be easier to review by looking at commits one at a time, which should be coherent.
Closes #33.