提交 dababf76 authored 作者: Serhij S's avatar Serhij S

tracing in comm

上级 37888d66
......@@ -13,6 +13,7 @@ use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering;
use std::sync::Arc;
use std::time::{Duration, Instant};
use tracing::trace;
/// Create a new serial client. The client will attempt to connect to the given address at the time
/// of the first request. The client will automatically reconnect if the connection is lost.
......@@ -214,10 +215,12 @@ impl Serial {
fn get_port(&self) -> Result<MutexGuard<SPort>> {
let mut lock = self.port.lock();
if lock.system_port.as_mut().is_none() {
trace!(dev=%self.params.port_dev, "creating new serial connection");
let port = open(&self.params, self.timeout)?;
lock.system_port.replace(port);
lock.last_frame.take();
self.session_id.fetch_add(1, Ordering::Release);
trace!(dev=%self.params.port_dev, session_id=self.session_id(), "serial connection started");
}
Ok(lock)
}
......
......@@ -12,6 +12,7 @@ use std::net::{SocketAddr, ToSocketAddrs};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
use std::time::Duration;
use tracing::trace;
const READER_CHANNEL_CAPACITY: usize = 1024;
......@@ -130,6 +131,7 @@ impl Tcp {
fn get_stream(&self) -> Result<MutexGuard<Option<TcpStream>>> {
let mut lock = self.stream.lock();
if lock.as_mut().is_none() {
trace!(addr=%self.addr, "creating new TCP stream");
let zero_to = Duration::from_secs(0);
let mut stream = if self.timeouts.connect > zero_to {
TcpStream::connect_timeout(&self.addr, self.timeouts.connect)?
......@@ -144,9 +146,11 @@ impl Tcp {
}
stream.set_nodelay(true)?;
if let Some(ref chat) = self.chat {
trace!("chatting with the server");
chat(&mut stream).map_err(Error::io)?;
}
self.session_id.fetch_add(1, Ordering::Release);
trace!(addr=%self.addr, session_id=self.session_id(), "TCP session started");
if let Some(ref tx) = self.reader_tx {
tx.send(CommReader {
reader: Some(Box::new(stream.try_clone()?)),
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论