Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature: -k flag (keep streaming new data to TCP connections) #34

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mik3y
Copy link

@mik3y mik3y commented Feb 4, 2021

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.

mik3y added 3 commits January 27, 2021 20:09
Uses pkg-config to locate libraries and headers where homebrew puts them.
When giving the `-T` flag, historical behavior is that the previously
received, buffered messages are streamed to the client, and then no
more. The socket is kept open until either the client closes it, or until
the client sends any data, at which point the client is disconnected.

When the `-k` flag is given in addition to the `-T` flag, an alternative
behavior is now implemented: As new messages are decoded, they
are sent to any attached clients in realtime. The client does not
need to disconnect to continue receiving updates.

Closes dgiardini#33
@dgiardini
Copy link
Owner

dgiardini commented Feb 6, 2021 via email

@mik3y
Copy link
Author

mik3y commented Feb 6, 2021

Hmm, that's a problem indeed. As an alternative, could write() to all connected clients synchronous with decode. Don't see great need for a thread per connection, so would do away with that too.

I don't have a windows environment to build/test with so I'll probably have to leave this to others.

@rvt
Copy link

rvt commented Oct 8, 2021

Could also enable the -k switch for *nix for the moment? At least that will help a set of users that want this.

@mik3y
Copy link
Author

mik3y commented Oct 8, 2021

@rvt if you want to use this right now, I have a project that incorporates my fork into a docker build. Should be usable: https://github.com/mik3y/rtl-ais-docker

I'm happy to take another swing at this change, but it'll take me at least a few days to find the time. As to approach, I'm still inclined to remove the unnecessary thread-per-connection & eliminate the internal signaling altogether.

@dgiardini
Copy link
Owner

dgiardini commented Oct 9, 2021 via email

@rvt
Copy link

rvt commented Oct 13, 2021

Hey Mike,

If I use your branch (https://github.com/mik3y/rtl-ais.git) will I get the version that keeps streaming with new connections?

I am working on a project where I cannot us the docker container but does the build, https://github.com/rvt/stratux/tree/stratux-ais and I need to have some guarantee that if a connection drops it will be picked up again.

@mik3y
Copy link
Author

mik3y commented Oct 13, 2021

Hi @rvt: Yes, my docker project points to my fork, here are the pertinent lines.

I'm not planning to touch that project again until resolving this issue (i.e. getting something officially merged), so feel free to use it directly or fork it.

@rvt
Copy link

rvt commented Oct 13, 2021

ok great,

Unfortunately I do not have a windows machine to test and modify code so I cannot help here... I will use your branch in the mean time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TCP server stops streaming; bug or intentional?
3 participants