Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ul] Recover API compatibility with 0.7.1 #582

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions ul/src/association/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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},
},
Expand All @@ -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};
Expand Down Expand Up @@ -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?;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions ul/src/association/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
31 changes: 27 additions & 4 deletions ul/src/pdu/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,34 @@ use dicom_encoding::text::{DefaultCharacterSetCodec, TextCodec};
use snafu::{ensure, OptionExt, ResultExt};
use tracing::warn;

pub type Result<T> = std::result::Result<T, ReadError>;
pub type Error = crate::pdu::ReadError;

pub type Result<T> = std::result::Result<T, Error>;

/// 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<Option<Pdu>> {
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 }
);

Expand Down Expand Up @@ -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!(
Expand Down
2 changes: 2 additions & 0 deletions ul/src/pdu/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = std::result::Result<T, WriteError>;

#[derive(Debug, Snafu)]
Expand Down