#![allow(dead_code)]
use crate::runtime::mailbox::MailboxSender as SessionCommandMailboxSender;
use crate::socket::connection_iface::ISocketConnection;
use crate::{error::ZmqError, Blob};
use std::fmt;
#[cfg(feature = "io-uring")]
use std::os::unix::io::RawFd;
use std::sync::Arc;
use fibre::oneshot;
use tokio::task::Id as TaskId;
#[cfg(feature = "inproc")]
use crate::message::FrameBatch;
#[cfg(feature = "inproc")]
use crate::transport::inproc::types::InprocHandshakeRequest;
#[cfg(feature = "inproc")]
use fibre::mpsc::BoundedAsyncReceiver;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ActorType {
SocketCore,
Listener,
AcceptLoop,
Session,
PipeReader,
Connecter,
ContextListener,
}
#[derive(Clone)]
pub enum SystemEvent {
ContextTerminating,
SocketClosing {
socket_id: usize,
},
ActorStarted {
handle_id: usize,
actor_type: ActorType,
parent_id: Option<usize>,
},
ActorStopping {
handle_id: usize,
actor_type: ActorType,
parent_id: Option<usize>,
endpoint_uri: Option<String>,
error: Option<ZmqError>,
},
PeerIdentityEstablished {
parent_core_id: usize,
connection_identifier: usize,
peer_identity: Option<Blob>,
peer_socket_type: Option<String>,
},
ConnectionAttemptFailed {
parent_core_id: usize,
target_endpoint_uri: String,
error: ZmqError,
},
#[cfg(feature = "inproc")]
InprocBindingRequest {
target_inproc_name: String,
connector_uri: String,
handshake_request: Arc<std::sync::Mutex<Option<InprocHandshakeRequest>>>,
},
}
impl fmt::Debug for SystemEvent {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
SystemEvent::ContextTerminating => write!(f, "ContextTerminating"),
SystemEvent::SocketClosing { socket_id } => f
.debug_struct("SocketClosing")
.field("socket_id", socket_id)
.finish(),
SystemEvent::ActorStarted {
handle_id,
actor_type,
parent_id,
} => f
.debug_struct("ActorStarted")
.field("handle_id", handle_id)
.field("actor_type", actor_type)
.field("parent_id", parent_id)
.finish(),
SystemEvent::ActorStopping {
handle_id,
actor_type,
endpoint_uri,
parent_id,
error,
} => f
.debug_struct("ActorStopping")
.field("handle_id", handle_id)
.field("actor_type", actor_type)
.field("parent_id", parent_id)
.field("endpoint_uri", endpoint_uri)
.field("error", error)
.finish(),
SystemEvent::PeerIdentityEstablished {
parent_core_id,
connection_identifier,
peer_identity,
peer_socket_type,
} => f
.debug_struct("PeerIdentityEstablished")
.field("parent_core_id", parent_core_id)
.field("connection_identifier", connection_identifier)
.field("peer_identity", peer_identity)
.field("peer_socket_type", peer_socket_type)
.finish(),
SystemEvent::ConnectionAttemptFailed {
parent_core_id,
target_endpoint_uri,
error,
} => f
.debug_struct("ConnectionAttemptFailed")
.field("parent_core_id", parent_core_id)
.field("target_endpoint_uri", target_endpoint_uri)
.field("error", error)
.finish(),
#[cfg(feature = "inproc")]
SystemEvent::InprocBindingRequest {
target_inproc_name,
connector_uri,
..
} => f
.debug_struct("InprocBindingRequest")
.field("target_inproc_name", target_inproc_name)
.field("connector_uri", connector_uri)
.finish_non_exhaustive(),
}
}
}
#[derive(Clone)] pub enum ConnectionInteractionModel {
ViaSca {
sca_mailbox: SessionCommandMailboxSender,
sca_handle_id: usize,
},
#[cfg(feature = "io-uring")]
ViaUringFd {
fd: RawFd,
},
#[cfg(not(feature = "io-uring"))]
ViaUringFd { _fd_placeholder: () },
#[cfg(feature = "inproc")]
ViaDirectInproc {
local_rx: Arc<std::sync::Mutex<Option<BoundedAsyncReceiver<FrameBatch>>>>,
peer_identity: Option<Blob>,
},
}
impl fmt::Debug for ConnectionInteractionModel {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ConnectionInteractionModel::ViaSca {
sca_mailbox,
sca_handle_id,
} => f
.debug_struct("ViaSca")
.field("sca_mailbox_closed", &sca_mailbox.is_closed())
.field("sca_handle_id", sca_handle_id)
.finish(),
#[cfg(feature = "io-uring")]
ConnectionInteractionModel::ViaUringFd { fd } => {
f.debug_struct("ViaUringFd").field("fd", fd).finish()
}
#[cfg(not(feature = "io-uring"))]
ConnectionInteractionModel::ViaUringFd { _fd_placeholder } => f
.debug_struct("ViaUringFd")
.field("_fd_placeholder", &())
.finish(),
#[cfg(feature = "inproc")]
ConnectionInteractionModel::ViaDirectInproc { .. } => {
f.debug_struct("ViaDirectInproc").finish_non_exhaustive()
}
}
}
}