diff --git a/ul/src/association/client.rs b/ul/src/association/client.rs index 8767276b..b966521b 100644 --- a/ul/src/association/client.rs +++ b/ul/src/association/client.rs @@ -103,12 +103,22 @@ pub enum Error { /// no presentation contexts accepted by the server NoAcceptedPresentationContexts { backtrace: Backtrace }, - /// failed to send PDU message + /// failed to write PDU message #[non_exhaustive] - Send { source: std::io::Error }, + Send { + #[snafu(backtrace)] + source: crate::pdu::writer::Error, + }, /// failed to send PDU message on wire #[non_exhaustive] + WireSend { + source: std::io::Error, + backtrace: Backtrace, + }, + + /// Operation timed out + #[non_exhaustive] Timeout { source: std::io::Error, backtrace: Backtrace, @@ -672,7 +682,7 @@ impl<'a> ClientAssociationOptions<'a> { // send request write_pdu(&mut buffer, &msg).context(SendRequestSnafu)?; - socket.write_all(&buffer).context(SendSnafu)?; + socket.write_all(&buffer).context(WireSendSnafu)?; buffer.clear(); let msg = get_client_pdu(&mut socket, MAXIMUM_PDU_SIZE, self.strict)?; @@ -941,7 +951,7 @@ where } .fail(); } - self.socket.write_all(&self.buffer).context(SendSnafu) + self.socket.write_all(&self.buffer).context(WireSendSnafu) } /// Read a PDU message from the other intervenient. @@ -1079,7 +1089,7 @@ pub mod non_blocking { ConnectSnafu, ConnectionClosedSnafu, MissingAbstractSyntaxSnafu, NoAcceptedPresentationContextsSnafu, ProtocolVersionMismatchSnafu, ReceiveResponseSnafu, ReceiveSnafu, RejectedSnafu, SendRequestSnafu, - ToAddressSnafu, UnexpectedResponseSnafu, UnknownResponseSnafu, + ToAddressSnafu, UnexpectedResponseSnafu, UnknownResponseSnafu, WireSendSnafu, }, pdata::non_blocking::{AsyncPDataWriter, PDataReader}, }, @@ -1092,7 +1102,7 @@ pub mod non_blocking { }; use super::{ - ClientAssociation, ClientAssociationOptions, CloseSocket, Release, Result, SendSnafu, + ClientAssociation, ClientAssociationOptions, CloseSocket, Release, Result, SendTooLongPduSnafu, TimeoutSnafu, }; use bytes::{Buf, BytesMut}; @@ -1268,7 +1278,7 @@ pub mod non_blocking { // send request write_pdu(&mut buffer, &msg).context(SendRequestSnafu)?; timeout(write_timeout, async { - socket.write_all(&buffer).await.context(SendSnafu)?; + socket.write_all(&buffer).await.context(WireSendSnafu)?; Ok(()) }) .await?; @@ -1323,7 +1333,7 @@ pub mod non_blocking { }, ); let _ = timeout(write_timeout, async { - socket.write_all(&buffer).await.context(SendSnafu) + socket.write_all(&buffer).await.context(WireSendSnafu) }) .await; buffer.clear(); @@ -1355,7 +1365,7 @@ pub mod non_blocking { }, ); let _ = timeout(write_timeout, async { - socket.write_all(&buffer).await.context(SendSnafu) + socket.write_all(&buffer).await.context(WireSendSnafu) }) .await; UnexpectedResponseSnafu { pdu }.fail() @@ -1369,7 +1379,7 @@ pub mod non_blocking { }, ); let _ = timeout(write_timeout, async { - socket.write_all(&buffer).await.context(SendSnafu) + socket.write_all(&buffer).await.context(WireSendSnafu) }) .await; UnknownResponseSnafu { pdu }.fail() @@ -1443,7 +1453,10 @@ pub mod non_blocking { .fail(); } timeout(self.write_timeout, async { - self.socket.write_all(&self.buffer).await.context(SendSnafu) + self.socket + .write_all(&self.buffer) + .await + .context(WireSendSnafu) }) .await } diff --git a/ul/src/association/mod.rs b/ul/src/association/mod.rs index 8463a86e..ffb84616 100644 --- a/ul/src/association/mod.rs +++ b/ul/src/association/mod.rs @@ -24,4 +24,7 @@ mod uid; pub(crate) mod pdata; pub use client::{ClientAssociation, ClientAssociationOptions}; +pub use pdata::{PDataReader, PDataWriter}; +#[cfg(feature = "async")] +pub use pdata::non_blocking::AsyncPDataWriter; pub use server::{ServerAssociation, ServerAssociationOptions}; diff --git a/ul/src/pdu/reader.rs b/ul/src/pdu/reader.rs index fabc5537..5024dc0e 100644 --- a/ul/src/pdu/reader.rs +++ b/ul/src/pdu/reader.rs @@ -5,11 +5,34 @@ use dicom_encoding::text::{DefaultCharacterSetCodec, TextCodec}; use snafu::{ensure, OptionExt, ResultExt}; use tracing::warn; -pub type Result = std::result::Result; +pub type Error = crate::pdu::ReadError; + +pub type Result = std::result::Result; + +/// The default maximum PDU size +#[deprecated(since = "0.7.2", note = "Use dicom_ul::pdu::DEFAULT_MAX_PDU instead")] +pub const DEFAULT_MAX_PDU: u32 = crate::pdu::DEFAULT_MAX_PDU; + +/// The minimum PDU size, +/// as specified by the standard +#[deprecated(since = "0.7.2", note = "Use dicom_ul::pdu::MINIMUM_PDU_SIZE instead")] +pub const MINIMUM_PDU_SIZE: u32 = crate::pdu::MINIMUM_PDU_SIZE; + +/// The maximum PDU size, +/// as specified by the standard +#[deprecated(since = "0.7.2", note = "Use dicom_ul::pdu::MAXIMUM_PDU_SIZE instead")] +pub const MAXIMUM_PDU_SIZE: u32 = crate::pdu::MAXIMUM_PDU_SIZE; + +/// The length of the PDU header in bytes, +/// comprising the PDU type (1 byte), +/// reserved byte (1 byte), +/// and PDU length (4 bytes). +#[deprecated(since = "0.7.2", note = "Use dicom_ul::pdu::PDU_HEADER_SIZE instead")] +pub const PDU_HEADER_SIZE: u32 = crate::pdu::PDU_HEADER_SIZE; pub fn read_pdu(mut buf: impl Buf, max_pdu_length: u32, strict: bool) -> Result> { ensure!( - (MINIMUM_PDU_SIZE..=MAXIMUM_PDU_SIZE).contains(&max_pdu_length), + (super::MINIMUM_PDU_SIZE..=super::MAXIMUM_PDU_SIZE).contains(&max_pdu_length), InvalidMaxPduSnafu { max_pdu_length } ); @@ -39,10 +62,10 @@ pub fn read_pdu(mut buf: impl Buf, max_pdu_length: u32, strict: bool) -> Result< ); } else if pdu_length > max_pdu_length { ensure!( - pdu_length <= MAXIMUM_PDU_SIZE, + pdu_length <= super::MAXIMUM_PDU_SIZE, PduTooLargeSnafu { pdu_length, - max_pdu_length: MAXIMUM_PDU_SIZE + max_pdu_length: super::MAXIMUM_PDU_SIZE } ); tracing::warn!( diff --git a/ul/src/pdu/writer.rs b/ul/src/pdu/writer.rs index 44be4272..ed2605e1 100644 --- a/ul/src/pdu/writer.rs +++ b/ul/src/pdu/writer.rs @@ -5,6 +5,8 @@ use dicom_encoding::text::TextCodec; use snafu::{Backtrace, ResultExt, Snafu}; use std::io::Write; +pub type Error = crate::pdu::WriteError; + pub type Result = std::result::Result; #[derive(Debug, Snafu)]