diff --git a/src/main.rs b/examples/demo3270.rs similarity index 91% rename from src/main.rs rename to examples/demo3270.rs index ea52d9d..d0ffa40 100644 --- a/src/main.rs +++ b/examples/demo3270.rs @@ -1,8 +1,7 @@ use structopt::StructOpt; use std::time::Duration; -mod tn3270; -mod encoding; +use tn3270s::tn3270; #[derive(StructOpt)] pub struct Cli { @@ -43,7 +42,9 @@ fn main() -> anyhow::Result<()> { } }; - run(session); + if let Err(err) = run(session) { + eprintln!("Error in session: {}", err); + } }); } diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..c16c060 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,2 @@ +pub mod tn3270; +mod encoding; diff --git a/src/tn3270.rs b/src/tn3270.rs index 4db9ff8..32eba3b 100644 --- a/src/tn3270.rs +++ b/src/tn3270.rs @@ -7,7 +7,6 @@ use libtelnet_rs::{ } }; use std::net::TcpStream; -use libtelnet_rs::telnet::op_option::EOR; use std::io::{Write, Read}; use std::time::Duration; @@ -124,14 +123,14 @@ impl Session { initial_negotiation.extend(self.parser._do(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 let mut idata = Vec::with_capacity(2000); idata.resize(idata.capacity(), 0); // 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() { let len = self.stream.read(&mut idata[..])?; @@ -143,6 +142,7 @@ impl Session { self.process_events(events)?; } + self.stream.set_read_timeout(None)?; Ok(true) } diff --git a/src/tn3270/stream.rs b/src/tn3270/stream.rs index f003956..97b2c84 100644 --- a/src/tn3270/stream.rs +++ b/src/tn3270/stream.rs @@ -160,7 +160,7 @@ bitflags! { } #[derive(Copy, Clone, Debug, Hash)] -enum Transparency { +pub enum Transparency { Default, Or, Xor,