d3270d now manages to connect and login with commands from netcat
This commit is contained in:
@@ -16,7 +16,7 @@ use tokio_stream::wrappers::{errors::BroadcastStreamRecvError, BroadcastStream};
|
||||
use tracing::{error, info, info_span, instrument, trace, warn, Instrument};
|
||||
|
||||
use d3270_common::b3270::indication::RunResult;
|
||||
use d3270_common::b3270::operation::Action;
|
||||
use d3270_common::b3270::operation::{Action, Run};
|
||||
use d3270_common::b3270::{operation, Indication, Operation};
|
||||
use d3270_common::tracker::{Disposition, Tracker};
|
||||
|
||||
@@ -194,11 +194,16 @@ impl B3270 {
|
||||
let (ind_chan, _) = broadcast::channel(100);
|
||||
|
||||
let mut write_buf = VecDeque::new();
|
||||
|
||||
// Queue any initial actions.
|
||||
for action in initial_actions {
|
||||
serde_json::to_writer(&mut write_buf, action).unwrap();
|
||||
write_buf.push_back(b'\n');
|
||||
}
|
||||
let act_str = serde_json::to_string(&Operation::Run(Run{
|
||||
actions: initial_actions.to_vec(),
|
||||
type_: Some("keybind".to_owned()),
|
||||
r_tag: None,
|
||||
})).unwrap();
|
||||
trace!(json=%act_str, "Writing initialization action");
|
||||
write_buf.extend(act_str.as_bytes());
|
||||
write_buf.push_back(b'\n');
|
||||
|
||||
let proc = B3270 {
|
||||
child,
|
||||
@@ -227,11 +232,11 @@ impl Future for B3270 {
|
||||
match buf {
|
||||
Ok(Some(line)) => match serde_json::from_str(&line) {
|
||||
Ok(ind) => {
|
||||
trace!(json = line, "Received indication");
|
||||
trace!(json = %line, "Received indication");
|
||||
indications.push(ind)
|
||||
}
|
||||
Err(error) => {
|
||||
warn!(%error, msg=line, "Failed to parse indication");
|
||||
warn!(%error, msg=%line, "Failed to parse indication");
|
||||
}
|
||||
},
|
||||
// EOF on stdin; this is a big problem
|
||||
|
||||
@@ -9,7 +9,9 @@ use anyhow::anyhow;
|
||||
use futures::future::select_all;
|
||||
use futures::FutureExt;
|
||||
use tokio::task::JoinHandle;
|
||||
use tracing::error;
|
||||
use tracing::{error, info};
|
||||
use tracing_subscriber::fmt::format::FmtSpan;
|
||||
use tracing_subscriber::prelude::*;
|
||||
|
||||
use d3270_common::b3270::operation::Action;
|
||||
|
||||
@@ -46,10 +48,26 @@ impl JoinHandleTagExt for JoinHandle<anyhow::Error> {
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
let mut subprocess_args = vec![OsString::from_str("-json").unwrap()];
|
||||
// Configure logging
|
||||
tracing_subscriber::registry()
|
||||
.with(tracing_subscriber::filter::EnvFilter::from_default_env())
|
||||
.with(
|
||||
tracing_subscriber::fmt::layer()
|
||||
.with_span_events(FmtSpan::ACTIVE)
|
||||
).init();
|
||||
|
||||
info!("Test");
|
||||
|
||||
let mut subprocess_args = vec![
|
||||
OsString::from_str("-json").unwrap(),
|
||||
OsString::from_str("-utf8").unwrap(),
|
||||
];
|
||||
let mut args_iter = std::env::args_os().peekable();
|
||||
let mut connect_str = None;
|
||||
let mut tcp_listen = None;
|
||||
|
||||
args_iter.next(); // skip program name.
|
||||
|
||||
while let Some(arg) = args_iter.next() {
|
||||
// we default to one of the ignored args
|
||||
match arg.to_str().unwrap_or("-json") {
|
||||
@@ -92,6 +110,7 @@ async fn main() -> anyhow::Result<()> {
|
||||
|
||||
let connect_str = connect_str.ok_or_else(|| anyhow!("No connect string given"))?;
|
||||
|
||||
info!(args=?subprocess_args, "Starting b3270");
|
||||
let subproc = tokio::process::Command::new("b3270")
|
||||
.args(&subprocess_args)
|
||||
.stdin(Stdio::piped())
|
||||
|
||||
@@ -6,16 +6,23 @@ use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader};
|
||||
use tokio::net::{TcpListener, TcpStream};
|
||||
use tokio::select;
|
||||
use tokio::task::JoinHandle;
|
||||
use tracing::{error, info, info_span, Instrument};
|
||||
use tracing::{error, info, info_span, Instrument, instrument};
|
||||
|
||||
use crate::arbiter::ArbiterHandleRequester;
|
||||
use crate::gen_connection::GenConnection;
|
||||
|
||||
#[instrument(skip(handle_requester))]
|
||||
pub async fn listener_proc(
|
||||
socket: SocketAddr,
|
||||
handle_requester: ArbiterHandleRequester,
|
||||
) -> anyhow::Result<JoinHandle<anyhow::Error>> {
|
||||
let listener = tokio::net::TcpListener::bind(socket.clone()).await?;
|
||||
let listener = match tokio::net::TcpListener::bind(socket.clone()).await {
|
||||
Err(error) => {
|
||||
error!(?socket, ?error, "Failed to bind");
|
||||
return Err(error.into());
|
||||
}
|
||||
Ok(listener) => listener
|
||||
};
|
||||
let span = info_span!(target: "connection-handling", "tcp_listener", addr=%socket);
|
||||
Ok(tokio::spawn(
|
||||
async move {
|
||||
|
||||
Reference in New Issue
Block a user