Skip to content

Conversation

@john-michaelburke
Copy link
Collaborator

@john-michaelburke john-michaelburke commented Jul 9, 2021

Implemented

  • Server state now not wrapped in arc-mutex.
  • Server state spawns connection thread in order to reconnect to same "Connection" object relies on channel.
  • Redid Connection object to be an enum for Tcp/File/SerialConnection types which implement ConnectionType trait.
  • Connection object now does not own the rdr/writers in order to be easier to clone. Whenever try_clone() is called it will create new rdr/wtr to be used.
  • Added logic to reconnect on internet dropout, may need to do more thorough testing for serial dropouts.

Unimplemented

@john-michaelburke john-michaelburke changed the title Unlimited Connection WIP. More reliable conn logic/serverstate->nonarcmutex[CPP-251] Jul 9, 2021
@john-michaelburke john-michaelburke force-pushed the john-michaelburke/unlimited_connection branch from 8187d24 to e5541f1 Compare July 9, 2021 22:14
@john-michaelburke john-michaelburke changed the title More reliable conn logic/serverstate->nonarcmutex[CPP-251] More reliable conn logic/serverstate->nonarcmutex[CPP-251] (WIP) Jul 9, 2021
let (rdr, _) = conn.into_io();
let mut main = MainTab::new(shared_state.clone(), client_send);
let realtime_delay = conn.realtime_delay();
let (rdr, _) = conn.try_connect(Some(shared_state.clone()))?;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have moved the creation of the reader/writer into process_messages here.

debug!("{}", e);
match e {
sbp::Error::IoError(err) => {
if (*err).kind() == ErrorKind::TimedOut {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach seems to work but may be a little finicky. Will likely need to switch to a match handling error types which correspond to logic we want to result in reconnection or closing the connection. As it is now it seems to handle internet dropping for TCP connections but exits if a serialport has a timeout.

@john-michaelburke john-michaelburke changed the title More reliable conn logic/serverstate->nonarcmutex[CPP-251] (WIP) More reliable conn logic/serverstate->nonarcmutex[CPP-251] Jul 10, 2021
@john-michaelburke john-michaelburke marked this pull request as ready for review July 10, 2021 01:44
pub rdr: Box<dyn io::Read + Send>,
pub wtr: Box<dyn io::Write + Send>,
#[derive(Clone)]
pub struct TcpConnection {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might be an opportunity to move connection related types to a new file, like connection.rs , possibly including ServerState?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I also renamed serverstate to ConnectionState as it seemed more fitting.

Comment on lines 1967 to 1986
trait ConnectionType {
fn close_when_done(&self) -> bool {
false
}
fn name(&self) -> String;
fn realtime_delay(&self) -> RealtimeDelay {
RealtimeDelay::Off
}
fn try_connect(
self,
shared_state: Option<SharedState>,
) -> Result<(Box<dyn io::Read + Send>, Box<dyn io::Write + Send>)>;
}

#[derive(Clone)]
pub enum Connection {
Tcp(TcpConnection),
File(FileConnection),
Serial(SerialConnection),
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need both the trait and the enum here, they kind of accomplish the same thing. I think you can just move the methods implemented in ConnectionType into regular impl blocks for TcpConnection, FileConnection and SerialConnection. Then you do the same dispatching inside of the Connection enum methods.

The other alternative would be to make things generic over ConnectionType and then drop the enum, but that seems a bit more complicated and imo not worth it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the trait. I'm not entirely sure what I was thinking here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean I think either way makes sense, I kind of like the enum here because we know all the variants beforehand, and then we don't have to sprinkle generic parameters everywhere

@john-michaelburke john-michaelburke force-pushed the john-michaelburke/unlimited_connection branch from 76efd2d to 23cc00d Compare July 12, 2021 18:10
@john-michaelburke john-michaelburke merged commit d7aa222 into main Jul 12, 2021
@john-michaelburke john-michaelburke deleted the john-michaelburke/unlimited_connection branch July 12, 2021 21:36
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.

3 participants