1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//! Cloneable producer for one exact connection's bounded command mailbox.
use std::io;
use bornera_core::OperationId;
use calandria::{Deadline, MailboxSender, TrySendError};
use crate::{ConnectionCommand, ConnectionToken};
/// Acknowledgement-free notification handle for one Bornera selector.
///
/// Each call reaches the underlying Mio waker. Producers must publish durable state
/// before pulsing, and the connection-set owner must drain or rescan that state.
#[derive(Clone, Debug)]
pub struct ConnectionPulseHandle {
pulse: calandria_mio::MioPulseHandle,
}
impl ConnectionPulseHandle {
pub(crate) fn new(pulse: calandria_mio::MioPulseHandle) -> Self {
Self { pulse }
}
/// Notifies the selector without a Calandria acknowledgement domain.
pub fn pulse(&self) -> io::Result<()> {
self.pulse.pulse()
}
}
/// Cross-thread producer bound to one generation-fenced connection.
///
/// Successful enqueue means only that the bounded set mailbox owns the
/// command. The authoritative confirmation for admission is
/// [`crate::ConnectionEvent::AdmissionOpened`].
#[derive(Clone, Debug)]
pub struct ConnectionPort {
connection: ConnectionToken,
sender: MailboxSender<ConnectionCommand>,
}
impl ConnectionPort {
pub(crate) const fn new(
connection: ConnectionToken,
sender: MailboxSender<ConnectionCommand>,
) -> Self {
Self { connection, sender }
}
/// Returns the exact set generation targeted by this producer.
pub const fn connection(&self) -> ConnectionToken {
self.connection
}
/// Queues admission opening after the caller has established its protocol session.
pub fn open_admission(&self) -> Result<(), TrySendError<ConnectionCommand>> {
self.sender
.try_send_control(ConnectionCommand::OpenAdmission {
connection: self.connection,
})
}
/// Queues explicit local cancellation of one accepted operation.
pub fn cancel(&self, operation: OperationId) -> Result<(), TrySendError<ConnectionCommand>> {
self.sender.try_send(ConnectionCommand::Cancel {
connection: self.connection,
operation,
})
}
/// Queues admission closure and operation plus transport draining through one deadline.
pub fn begin_drain(&self, deadline: Deadline) -> Result<(), TrySendError<ConnectionCommand>> {
self.sender.try_send_control(ConnectionCommand::BeginDrain {
connection: self.connection,
deadline,
})
}
/// Queues forced mechanical closure, preempting transport-local graceful shutdown.
pub fn close(&self) -> Result<(), TrySendError<ConnectionCommand>> {
self.sender.try_send_control(ConnectionCommand::Close {
connection: self.connection,
})
}
}