@@ -16,6 +16,7 @@ use opcua_core::comms::{
1616use opcua_types:: { Error , StatusCode } ;
1717
1818use crate :: transport:: state:: SecureChannelState ;
19+ use crate :: transport:: RequestRecv ;
1920
2021#[ derive( Debug ) ]
2122struct MessageChunkWithChunkInfo {
@@ -29,13 +30,14 @@ pub(crate) struct MessageState {
2930 deadline : Instant ,
3031}
3132
32- pub ( super ) struct TransportState {
33+ /// Internal state of a transport implementation.
34+ pub struct TransportState {
3335 /// Channel for outgoing requests. Will only be polled if the number of inflight requests is below the limit.
3436 outgoing_recv : tokio:: sync:: mpsc:: Receiver < OutgoingMessage > ,
3537 /// State of pending requests
3638 message_states : HashMap < u32 , MessageState > ,
3739 /// Secure channel
38- pub ( super ) channel_state : Arc < SecureChannelState > ,
40+ pub channel_state : Arc < SecureChannelState > ,
3941 /// Max pending incoming messages
4042 max_chunk_count : usize ,
4143 /// Last decoded sequence number
@@ -45,6 +47,13 @@ pub(super) struct TransportState {
4547 receive_buffer_size : usize ,
4648}
4749
50+ #[ derive( Debug , Clone , Copy ) ]
51+ pub ( super ) enum TransportCloseState {
52+ Open ,
53+ Closing ( StatusCode ) ,
54+ Closed ( StatusCode ) ,
55+ }
56+
4857#[ derive( Debug ) ]
4958/// Result of polling a transport implementation.
5059/// This represents a single iteration of the transport event loop.
@@ -62,16 +71,21 @@ pub enum TransportPollResult {
6271 Closed ( StatusCode ) ,
6372}
6473
74+ /// An outgoing message to be sent by the transport.
6575pub struct OutgoingMessage {
76+ /// The actual request message to send.
6677 pub request : RequestMessage ,
78+ /// A callback that should be called when a response is received.
6779 pub callback : Option < tokio:: sync:: oneshot:: Sender < Result < ResponseMessage , StatusCode > > > ,
80+ /// Deadline for the request.
6881 pub deadline : Instant ,
6982}
7083
7184impl TransportState {
72- pub ( super ) fn new (
85+ /// Create a new transport state.
86+ pub fn new (
7387 channel_state : Arc < SecureChannelState > ,
74- outgoing_recv : tokio :: sync :: mpsc :: Receiver < OutgoingMessage > ,
88+ outgoing_recv : RequestRecv ,
7589 max_chunk_count : usize ,
7690 receive_buffer_size : usize ,
7791 ) -> Self {
@@ -91,7 +105,7 @@ impl TransportState {
91105 }
92106
93107 /// Wait for an outgoing message. Will also check for timed out messages.
94- pub ( super ) async fn wait_for_outgoing_message (
108+ pub async fn wait_for_outgoing_message (
95109 & mut self ,
96110 send_buffer : & mut SendBuffer ,
97111 ) -> Option < ( RequestMessage , u32 ) > {
@@ -124,7 +138,7 @@ impl TransportState {
124138 }
125139
126140 /// Store incoming messages in the message state.
127- pub ( super ) fn handle_incoming_message ( & mut self , message : Message ) -> Result < ( ) , StatusCode > {
141+ pub fn handle_incoming_message ( & mut self , message : Message ) -> Result < ( ) , StatusCode > {
128142 let status = match message {
129143 Message :: Acknowledge ( ack) => {
130144 debug ! ( "Reader got an unexpected ack {:?}" , ack) ;
@@ -151,7 +165,9 @@ impl TransportState {
151165 }
152166 }
153167
154- pub ( super ) fn message_send_failed ( & mut self , request_id : u32 , err : StatusCode ) {
168+ /// Call this if sending a message fails. This will notify the waiting request
169+ /// that the message could not be sent.
170+ pub fn message_send_failed ( & mut self , request_id : u32 , err : StatusCode ) {
155171 if let Some ( message_state) = self . message_states . remove ( & request_id) {
156172 let _ = message_state. callback . send ( Err ( err) ) ;
157173 }
@@ -314,7 +330,7 @@ impl TransportState {
314330 /// Close the transport, aborting any pending requests.
315331 /// If `status` is good, the pending requests will be terminated with
316332 /// `BadConnectionClosed`.
317- pub ( super ) async fn close ( & mut self , status : StatusCode ) -> StatusCode {
333+ pub async fn close ( & mut self , status : StatusCode ) -> StatusCode {
318334 // If the status is good, we still want to send a bad status code
319335 // to the pending requests. They didn't succeed, after all.
320336 let request_status = if status. is_good ( ) {
0 commit comments