Made it a library, as I should have done from the beginning

This commit is contained in:
2020-11-11 15:44:27 +01:00
parent de3c663ccd
commit c294e8033f
4 changed files with 10 additions and 7 deletions

View File

@@ -1,8 +1,7 @@
use structopt::StructOpt; use structopt::StructOpt;
use std::time::Duration; use std::time::Duration;
mod tn3270; use tn3270s::tn3270;
mod encoding;
#[derive(StructOpt)] #[derive(StructOpt)]
pub struct Cli { pub struct Cli {
@@ -43,7 +42,9 @@ fn main() -> anyhow::Result<()> {
} }
}; };
run(session); if let Err(err) = run(session) {
eprintln!("Error in session: {}", err);
}
}); });
} }

2
src/lib.rs Normal file
View File

@@ -0,0 +1,2 @@
pub mod tn3270;
mod encoding;

View File

@@ -7,7 +7,6 @@ use libtelnet_rs::{
} }
}; };
use std::net::TcpStream; use std::net::TcpStream;
use libtelnet_rs::telnet::op_option::EOR;
use std::io::{Write, Read}; use std::io::{Write, Read};
use std::time::Duration; use std::time::Duration;
@@ -124,14 +123,14 @@ impl Session {
initial_negotiation.extend(self.parser._do(tn_opt::TTYPE)); initial_negotiation.extend(self.parser._do(tn_opt::TTYPE));
initial_negotiation.extend(self.parser._will(tn_opt::TTYPE)); initial_negotiation.extend(self.parser._will(tn_opt::TTYPE));
self.process_events(initial_negotiation); self.process_events(initial_negotiation)?;
// Large enough for a TCP packet // Large enough for a TCP packet
let mut idata = Vec::with_capacity(2000); let mut idata = Vec::with_capacity(2000);
idata.resize(idata.capacity(), 0); idata.resize(idata.capacity(), 0);
// Make sure that negotiation completes quickly // Make sure that negotiation completes quickly
self.stream.set_read_timeout(Some(Duration::from_secs(5))); self.stream.set_read_timeout(Some(Duration::from_secs(5)))?;
while !self.is_ready() { while !self.is_ready() {
let len = self.stream.read(&mut idata[..])?; let len = self.stream.read(&mut idata[..])?;
@@ -143,6 +142,7 @@ impl Session {
self.process_events(events)?; self.process_events(events)?;
} }
self.stream.set_read_timeout(None)?;
Ok(true) Ok(true)
} }

View File

@@ -160,7 +160,7 @@ bitflags! {
} }
#[derive(Copy, Clone, Debug, Hash)] #[derive(Copy, Clone, Debug, Hash)]
enum Transparency { pub enum Transparency {
Default, Default,
Or, Or,
Xor, Xor,