Skip to content

Commit

Permalink
Add missing listener, connection, and stream event structures (#4731)
Browse files Browse the repository at this point in the history
  • Loading branch information
masa-koz authored Jan 1, 2025
1 parent b6ebb83 commit 526944c
Showing 1 changed file with 122 additions and 18 deletions.
140 changes: 122 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,19 +910,35 @@ pub const PARAM_STREAM_PRIORITY: u32 = 0x08000003;

pub type ListenerEventType = u32;
pub const LISTENER_EVENT_NEW_CONNECTION: ListenerEventType = 0;
pub const LISTENER_EVENT_STOP_COMPLETE: ListenerEventType = 1;

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ListenerEventNewConnection {
pub info: *const NewConnectionInfo,
pub connection: Handle,
pub new_negotiated_alpn: *const u8,
}

bitfield! {
#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct ListenerEventStopCompleteBitfields(u8);
// The fields default to u8
pub app_close_in_progress, _: 0, 0;
_reserved, _: 7, 1;
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ListenerEventStopComplete {
pub bit_flags: ListenerEventStopCompleteBitfields,
}

#[repr(C)]
#[derive(Copy, Clone)]
pub union ListenerEventPayload {
pub new_connection: ListenerEventNewConnection,
pub stop_complete: ListenerEventStopComplete,
}

#[repr(C)]
Expand Down Expand Up @@ -974,10 +990,33 @@ pub struct ConnectionEventConnectionShutdownByPeer {
pub error_code: u62,
}

bitfield! {
#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct ConnectionEventShutdownCompleteBitfields(BOOLEAN);
// The fields default to BOOLEAN
pub handshake_completed, _: 0, 0;
pub peer_acknowledged_shutdown, _: 1, 1;
pub app_close_in_progress, _: 2, 2;
_reserved, _: 7, 3;
}

#[repr(C, packed)]
#[derive(Debug, Copy, Clone)]
pub struct ConnectionEventShutdownComplete {
pub _bitfield: BOOLEAN,
pub bit_flags: ConnectionEventShutdownCompleteBitfields,
}

#[repr(C, packed)]
#[derive(Debug, Copy, Clone)]
pub struct ConnectionEventLocalAddressChanged {
pub address: *const Addr,
}

#[repr(C, packed)]
#[derive(Debug, Copy, Clone)]
pub struct ConnectionEventPeerAddressChanged {
pub address: *const Addr,
}

#[repr(C)]
Expand All @@ -987,6 +1026,33 @@ pub struct ConnectionEventPeerStreamStarted {
pub flags: StreamOpenFlags,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ConnectionEventStreamsAvailable {
pub bidirectional_count: u16,
pub unidirectional_count: u16,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ConnectionEventPeerNeedsStreams {
pub bidirectional: BOOLEAN,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ConnectionEventIdealProcessorChanged {
pub ideal_processor: u16,
pub partition_index: u16,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ConnectionEventDatagramStateChanged {
pub send_enabled: BOOLEAN,
pub max_send_length: u16,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ConnectionEventDatagramReceived {
Expand All @@ -1001,31 +1067,48 @@ pub struct ConnectionEventDatagramSendStateChanged {
pub state: DatagramSendState,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ConnectionEventResumed {
pub resumption_state_length: u16,
pub resumption_state: *const u8,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ConnectionEventResumptionTicketReceived {
pub resumption_ticket_length: u32,
pub resumption_ticket: *const u8,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ConnectionEventPeerCertificateReceived {
pub certificate: *const Certificate,
pub deferred_error_flags: u32,
pub deferred_status: u32,
pub chain: *const CertificateChain,
}

#[repr(C)]
#[derive(Copy, Clone)]
pub union ConnectionEventPayload {
pub connected: ConnectionEventConnected,
pub shutdown_initiated_by_transport: ConnectionEventConnectionShutdownByTransport,
pub shutdown_initiated_by_peer: ConnectionEventConnectionShutdownByPeer,
pub shutdown_complete: ConnectionEventShutdownComplete,
//pub local_address_changed: ConnectionEventLocalAddressChanged,
//pub peer_address_changed: ConnectionEventPeerAddressChanged,
pub local_address_changed: ConnectionEventLocalAddressChanged,
pub peer_address_changed: ConnectionEventPeerAddressChanged,
pub peer_stream_started: ConnectionEventPeerStreamStarted,
//pub streams_available: ConnectionEventStreamsAvailable,
//pub ideal_processor_changed: ConnectionEventIdealProcessorChanged,
//pub datagram_state_changed: ConnectionEventDatagramStateChanged,
pub streams_available: ConnectionEventStreamsAvailable,
pub peer_needs_streams: ConnectionEventPeerNeedsStreams,
pub ideal_processor_changed: ConnectionEventIdealProcessorChanged,
pub datagram_state_changed: ConnectionEventDatagramStateChanged,
pub datagram_received: ConnectionEventDatagramReceived,
pub datagram_send_state_changed: ConnectionEventDatagramSendStateChanged,
//pub resumed: ConnectionEventResumed,
pub resumed: ConnectionEventResumed,
pub resumption_ticket_received: ConnectionEventResumptionTicketReceived,
//pub peer_certificated_received: ConnectionEventPeerCertificateReceived,
pub peer_certificated_received: ConnectionEventPeerCertificateReceived,
}

#[repr(C)]
Expand All @@ -1049,13 +1132,23 @@ pub const STREAM_EVENT_SEND_SHUTDOWN_COMPLETE: StreamEventType = 6;
pub const STREAM_EVENT_SHUTDOWN_COMPLETE: StreamEventType = 7;
pub const STREAM_EVENT_IDEAL_SEND_BUFFER_SIZE: StreamEventType = 8;
pub const STREAM_EVENT_PEER_ACCEPTED: StreamEventType = 9;
pub const STREAM_EVENT_CANCEL_ON_LOSS: StreamEventType = 10;

bitfield! {
#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct StreamEventStartCompleteBitfields(u8);
// The fields default to u8
pub peer_accepted, _: 0, 0;
_reserved, _: 7, 1;
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct StreamEventStartComplete {
pub status: u64,
pub status: u32,
pub id: u62,
pub bit_flags: u8,
pub bit_flags: StreamEventStartCompleteBitfields,
}

#[repr(C)]
Expand All @@ -1078,13 +1171,13 @@ pub struct StreamEventSendComplete {
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct StreamEventPeerSendAborted {
pub error_code: u64,
pub error_code: u62,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct StreamEventPeerReceiveAborted {
pub error_code: u64,
pub error_code: u62,
}

#[repr(C)]
Expand All @@ -1096,17 +1189,21 @@ pub struct StreamEventSendShutdownComplete {
bitfield! {
#[repr(C)]
#[derive(Clone, Copy)]
struct StreamEventShutdownCompleteBitfields(u8);
pub struct StreamEventShutdownCompleteBitfields(u8);
// The fields default to u8
app_close_in_progress, _: 1, 0;
_reserved, _: 7, 1;
pub app_close_in_progress, _: 0, 0;
pub conn_shutdown_by_app, _: 1, 1;
pub conn_closed_remotely, _: 2, 2;
_reserved, _: 7, 3;
}

#[repr(C)]
#[derive(Copy, Clone)]
pub struct StreamEventShutdownComplete {
connection_shutdown: bool,
flags: StreamEventShutdownCompleteBitfields,
pub connection_shutdown: bool,
pub bit_flags: StreamEventShutdownCompleteBitfields,
pub connection_error_code: u62,
pub connection_close_status: u32,
}

#[repr(C)]
Expand All @@ -1115,6 +1212,12 @@ pub struct StreamEventIdealSendBufferSize {
pub byte_count: u64,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct StreamEventCancelOnLoss {
pub error_code: u62,
}

#[repr(C)]
#[derive(Copy, Clone)]
pub union StreamEventPayload {
Expand All @@ -1126,6 +1229,7 @@ pub union StreamEventPayload {
pub send_shutdown_complete: StreamEventSendShutdownComplete,
pub shutdown_complete: StreamEventShutdownComplete,
pub ideal_send_buffer_size: StreamEventIdealSendBufferSize,
pub cancel_on_loss: StreamEventCancelOnLoss,
}

#[repr(C)]
Expand Down

0 comments on commit 526944c

Please sign in to comment.