silk/native_socket
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, x86_64-unknown-linux-gnu.
Scoped nonblocking TCP and pathname-Unix connections and listeners over ByteDuplex.
When to use
Use connectResolvedOwned or connectUnixOwned when the caller must retain an outbound connection. The shorter connectResolved and connectUnix operations consume the same owner into a protected callback scope. Use listen or listenUnix for one affine listener, then accept one independently owned Connection at a time.
Details
Every native syscall is nonblocking. Temporary unavailability uses zero-time poll followed by a positive MonotonicClock wait. One acquisition deadline is shared by every sequential candidate or accept retry. Socket flush means kernel acceptance, not delivery to the peer.
Gotchas
Timer polling trades readiness latency for a bounded idle poll rate. A None deadline may wait indefinitely. Listener close never unlinks a pathname. Structured Effect exits close once; fatal traps carry no cleanup guarantee. Darwin setup is single-threaded and does not promise cross-thread fork safety.
Import as NativeSocket with import silk.native_socket { NativeSocket }.
Public declarations: 33.
ConnectionPhase
pub enum ConnectionPhaseThe visible directional lifetime of one native connection.
Connecting
Connecting = 0Native connection establishment has not completed.
Open
Open = 1The descriptor is available for its permitted operations.
WriteClosed
WriteClosed = 2The local write direction is closed; reads remain available.
Closed
Closed = 3The descriptor is terminally closed.
NativeSocketOperation
pub enum NativeSocketOperationThe native boundary that produced a socket failure.
Socket
Socket = 0Native socket creation.
Configure
Configure = 1Native descriptor or socket-option setup.
Connect
Connect = 2Native outbound connection establishment.
Bind
Bind = 3Native local-address binding.
Listen
Listen = 4Native listener activation.
GetSocketName
GetSocketName = 5Native bound-address inspection.
Accept
Accept = 6Native incoming connection acceptance.
ConvertAddress
ConvertAddress = 7Conversion of a returned native address.
Poll
Poll = 8Native zero-time readiness inspection.
GetSocketOption
GetSocketOption = 9Native socket error inspection.
Read
Read = 10Native input transfer.
Write
Write = 11Native output transfer.
ShutdownWrite
ShutdownWrite = 12Native write-direction shutdown.
Close
Close = 13Native terminal descriptor release.
ListenerPhase
pub enum ListenerPhaseThe visible lifetime of one native listener.
Open
Open = 0The descriptor is available for its permitted operations.
Closed
Closed = 1The descriptor is terminally closed.
ListenOptionsReason
pub enum ListenOptionsReasonThe rejected ListenOptions field.
KernelBacklog
KernelBacklog = 0The kernel backlog is outside 1..65535.
PollInterval
PollInterval = 1The polling interval is outside 1..1,000,000,000 nanoseconds.
ListenOptionsError
pub struct ListenOptionsErrorA typed ListenOptions admission failure.
Field reason
pub reason: ListenOptionsReasonThe input admission rule that failed.
Field value
pub value: u64The rejected option value.
InvalidBindReason
pub enum InvalidBindReasonThe rejected local pathname condition.
EmptyPath
EmptyPath = 0The pathname contains no bytes.
RelativePath
RelativePath = 1The pathname does not start with a slash.
NulPath
NulPath = 2The pathname contains a NUL byte.
AbstractPath
AbstractPath = 3The pathname requests an unsupported abstract address.
ConnectOptionsReason
pub enum ConnectOptionsReasonThe rejected ConnectOptions field.
PollInterval
PollInterval = 0The polling interval is outside 1..1,000,000,000 nanoseconds.
MaxAttempts
MaxAttempts = 1The connection attempt limit is outside 1..1024.
ConnectOptionsError
pub struct ConnectOptionsErrorA typed ConnectOptions admission failure.
Field reason
pub reason: ConnectOptionsReasonThe input admission rule that failed.
Field value
pub value: u64The rejected option value.
InvalidEndpointReason
pub enum InvalidEndpointReasonThe rejected endpoint or pathname condition.
EmptyEndpoints
EmptyEndpoints = 0The endpoint list is empty.
TooManyEndpoints
TooManyEndpoints = 1The endpoint count exceeds the attempt limit.
EmptyPath
EmptyPath = 2The pathname contains no bytes.
RelativePath
RelativePath = 3The pathname does not start with a slash.
NulPath
NulPath = 4The pathname contains a NUL byte.
PathTooLong
PathTooLong = 5The pathname and its terminator exceed native address capacity.
AbstractPath
AbstractPath = 6The pathname requests an unsupported abstract address.
AttemptFailure
pub union AttemptFailureOne nonrecursive failure retained when the attempt budget is exhausted.
ConnectionRefused
AttemptFailure.ConnectionRefused: AttemptFailureThe peer refused the connection.
NetworkUnreachable
AttemptFailure.NetworkUnreachable: AttemptFailureThe destination network is unreachable.
AddressUnavailable
AttemptFailure.AddressUnavailable: AttemptFailureThe requested address is unavailable.
NativeFailure
AttemptFailure.NativeFailure { operation: NativeSocketOperation, errno: i32 }: AttemptFailureA native boundary failed with the retained operation and error number.
Field operation
pub operation: NativeSocketOperationThe native or byte-I/O operation that failed.
Field errno
pub errno: i32The native error number reported by the selected platform.
NativeSocketError
pub union NativeSocketErrorA native socket acquisition or explicit lifecycle failure.
AttemptsExhausted
NativeSocketError.AttemptsExhausted { attempted: usize, last: AttemptFailure }: NativeSocketErrorThe admitted connection attempt budget is exhausted.
Field attempted
pub attempted: usizeThe number of native connect attempts already made.
Field last
pub last: AttemptFailureThe failure from the final attempted candidate.
TimeRangeError
NativeSocketError.TimeRangeError: NativeSocketErrorThe next positive wake time is not representable.
InvalidEndpoint
NativeSocketError.InvalidEndpoint { reason: InvalidEndpointReason, offset: usize, limit: usize }: NativeSocketErrorAn endpoint list or Unix pathname failed admission.
Field reason
pub reason: InvalidEndpointReasonThe input admission rule that failed.
Field offset
pub offset: usizeThe zero-based byte offset of the rejected pathname input.
Field limit
pub limit: usizeThe admitted maximum for this input or transfer.
InvalidBindAddress
NativeSocketError.InvalidBindAddress { reason: InvalidBindReason, offset: usize }: NativeSocketErrorA Unix bind pathname failed admission.
Field reason
pub reason: InvalidBindReasonThe input admission rule that failed.
Field offset
pub offset: usizeThe zero-based byte offset of the rejected pathname input.
PathTooLong
NativeSocketError.PathTooLong { length: usize, limit: usize }: NativeSocketErrorThe pathname and its terminator exceed native address capacity.
Field length
pub length: usizeThe pathname or returned native address length in bytes.
Field limit
pub limit: usizeThe admitted maximum for this input or transfer.
AddressInUse
NativeSocketError.AddressInUse: NativeSocketErrorThe requested local address is already in use.
InvalidNativeAddress
NativeSocketError.InvalidNativeAddress { family: i32, length: usize }: NativeSocketErrorThe returned native address has an invalid family or length.
Field family
pub family: i32The native address family, or -1 when the header is too short.
Field length
pub length: usizeThe pathname or returned native address length in bytes.
UnsupportedPeerAddress
NativeSocketError.UnsupportedPeerAddress { family: i32, length: usize }: NativeSocketErrorThe returned peer uses an unsupported address form.
Field family
pub family: i32The native address family, or -1 when the header is too short.
Field length
pub length: usizeThe pathname or returned native address length in bytes.
FamilyUnsupported
NativeSocketError.FamilyUnsupported: NativeSocketErrorThe requested address family is unsupported.
PermissionDenied
NativeSocketError.PermissionDenied: NativeSocketErrorThe operating system denied the operation.
ConnectionRefused
NativeSocketError.ConnectionRefused: NativeSocketErrorThe peer refused the connection.
NetworkUnreachable
NativeSocketError.NetworkUnreachable: NativeSocketErrorThe destination network is unreachable.
AddressUnavailable
NativeSocketError.AddressUnavailable: NativeSocketErrorThe requested address is unavailable.
SystemResources
NativeSocketError.SystemResources: NativeSocketErrorThe operating system cannot supply the required resources.
Timeout
NativeSocketError.Timeout: NativeSocketErrorThe supplied absolute deadline has been reached.
Closed
NativeSocketError.Closed: NativeSocketErrorThe descriptor is terminally closed.
WriteClosed
NativeSocketError.WriteClosed: NativeSocketErrorThe local write direction is closed; reads remain available.
InvalidTransferCount
NativeSocketError.InvalidTransferCount { operation: ByteIoOperation, count: usize, limit: usize }: NativeSocketErrorA native success reported an impossible transfer count.
Field operation
pub operation: ByteIoOperationThe native or byte-I/O operation that failed.
Field count
pub count: usizeThe invalid successful transfer count reported by the native operation.
Field limit
pub limit: usizeThe admitted maximum for this input or transfer.
NativeFailure
NativeSocketError.NativeFailure { operation: NativeSocketOperation, errno: i32 }: NativeSocketErrorA native boundary failed with the retained operation and error number.
Field operation
pub operation: NativeSocketOperationThe native or byte-I/O operation that failed.
Field errno
pub errno: i32The native error number reported by the selected platform.
NativeSocket
pub struct NativeSocketNamespace anchor for the selected native socket actor.
ConnectOptions
pub struct ConnectOptionsFinite readiness and attempt policy copied into one connection.
Associated function ConnectOptions.make
pub fn make(noDelay: bool, pollIntervalNanoseconds: u64, maxAttempts: usize) -> silk/result.Result<silk/native_socket.ConnectOptions, silk/native_socket.ConnectOptionsError>Admits a 1..1,000,000,000ns interval and 1..1024 native attempts.
Associated function ConnectOptions.defaults
pub fn defaults() -> ConnectOptionsSelects Nagle, a one-millisecond readiness interval, and 64 attempts.
Method ConnectOptions.noDelay
pub fn noDelay<'life0>(self: &'life0 ConnectOptions) -> boolReports whether outbound TCP disables Nagle buffering.
Method ConnectOptions.pollInterval
pub fn pollInterval<'life0>(self: &'life0 ConnectOptions) -> u64Returns the positive polling interval in nanoseconds.
Method ConnectOptions.maxAttempts
pub fn maxAttempts<'life0>(self: &'life0 ConnectOptions) -> usizeReturns the maximum number of native connection attempts.
ListenOptions
pub struct ListenOptionsFinite kernel admission and cooperative accept policy.
Associated function ListenOptions.make
pub fn make(kernelBacklog: usize, reuseAddress: bool, pollIntervalNanoseconds: u64) -> silk/result.Result<silk/native_socket.ListenOptions, silk/native_socket.ListenOptionsError>Admits backlog 1..65535 and a 1..1,000,000,000ns polling interval.
Associated function ListenOptions.defaults
pub fn defaults() -> ListenOptionsSelects backlog 128, no address reuse, and a one-millisecond polling interval.
Method ListenOptions.kernelBacklog
pub fn kernelBacklog<'life0>(self: &'life0 ListenOptions) -> usizeReturns the requested kernel backlog limit.
Method ListenOptions.reuseAddress
pub fn reuseAddress<'life0>(self: &'life0 ListenOptions) -> boolReports whether listener creation enables SO_REUSEADDR.
Method ListenOptions.pollInterval
pub fn pollInterval<'life0>(self: &'life0 ListenOptions) -> u64Returns the positive polling interval in nanoseconds.
UnixSocketPath
pub struct UnixSocketPathOne owned pathname spelling used by listener metadata.
Method UnixSocketPath.bytes
pub fn bytes<'life0>(self: &'life0 UnixSocketPath) -> &'life0 [u8]Borrows the exact owned pathname spelling.
BoundAddress
pub union BoundAddressThe actual local address owned by a published listener.
Tcp
BoundAddress.Tcp { endpoint: Endpoint }: BoundAddressAn owned numeric TCP endpoint.
Field endpoint
pub endpoint: EndpointThe owned numeric address and port.
Unix
BoundAddress.Unix { path: UnixSocketPath }: BoundAddressAn owned Unix-domain address.
Field path
pub path: UnixSocketPathThe owned Unix pathname spelling.
UnixPeerAddress
pub union UnixPeerAddressThe peer identity returned for one accepted Unix connection.
Unnamed
UnixPeerAddress.Unnamed: UnixPeerAddressThe peer has no bound pathname.
Pathname
UnixPeerAddress.Pathname { path: UnixSocketPath }: UnixPeerAddressThe peer has an owned pathname spelling.
Field path
pub path: UnixSocketPathThe owned Unix pathname spelling.
PeerAddress
pub union PeerAddressThe owned peer identity returned with one accepted connection.
Tcp
PeerAddress.Tcp { endpoint: Endpoint }: PeerAddressAn owned numeric TCP endpoint.
Field endpoint
pub endpoint: EndpointThe owned numeric address and port.
Unix
PeerAddress.Unix { peer: UnixPeerAddress }: PeerAddressAn owned Unix-domain address.
Field peer
pub peer: UnixPeerAddressThe accepted peer identity.
Implementation Copy for ConnectOptionsError
impl Copy for ConnectOptionsErrorImplementation Copy for AttemptFailure
impl Copy for AttemptFailureImplementation Copy for NativeSocketError
impl Copy for NativeSocketErrorImplementation Copy for ConnectOptions
impl Copy for ConnectOptionsImplementation Copy for ListenOptionsError
impl Copy for ListenOptionsErrorImplementation Copy for ListenOptions
impl Copy for ListenOptionsImplementation Copy for UnixSocketPath
impl Copy for UnixSocketPathImplementation Copy for BoundAddress
impl Copy for BoundAddressImplementation Copy for UnixPeerAddress
impl Copy for UnixPeerAddressImplementation Copy for PeerAddress
impl Copy for PeerAddressConnection
pub struct ConnectionOne affine native descriptor lent only inside a connection callback.
Method Connection.phase
pub fn phase<'life0>(self: &'life0 Connection) -> ConnectionPhaseReturns the current descriptor lifecycle phase.
Method Connection.close
pub effect<'life0> fn close<'life0>(self: &'life0 mut Connection) -> () ! NativeSocketErrorExplicitly closes this connection once. Scoped cleanup recovers this error.
Listener
pub struct ListenerOne affine native listening descriptor and its validated local identity.
Method Listener.phase
pub fn phase<'life0>(self: &'life0 Listener) -> ListenerPhaseReturns the current descriptor lifecycle phase.
Method Listener.boundAddress
pub fn boundAddress<'life0>(self: &'life0 Listener) -> BoundAddressReturns a copy of the actual local address recorded after listener creation.
Method Listener.close
pub effect<'life0> fn close<'life0>(self: &'life0 mut Listener) -> () ! NativeSocketErrorExplicitly closes this listener once without unlinking a Unix pathname.
Accepted
pub struct AcceptedOne independently owned accepted connection and peer identity.
Method Accepted.peer
pub fn peer<'life0>(self: &'life0 Accepted) -> PeerAddressReturns a copy of the independently owned accepted peer identity.
Method Accepted.connectionPhase
pub fn connectionPhase<'life0>(self: &'life0 Accepted) -> ConnectionPhaseReturns the accepted connection lifecycle phase.
AcceptedView
pub struct AcceptedView<'a>The higher-ranked loans available only inside one accepted-result scope.
Field connection
pub connection: &'a mut silk/native_socket.ConnectionThe exclusive connection loan valid only within this accepted-result scope.
Field peer
pub peer: &'a silk/native_socket.PeerAddressThe accepted peer identity.
AcceptedContext
pub interface AcceptedContext<A, E, ?CallbackRequirements, ?ContextRequirements>Compile-time adapter from one owned context to an accepted-connection use.
Details
Implement this interface when the scoped use owns affine or once-callable state. The first row
preserves caller-selected requirements and the second records requirements introduced by the
concrete context. Selection adds no runtime service or requirement-row member: context is
consumed once and the accepted loans remain independently higher-ranked.
Operation use
effect<'call> fn use<'call: 'call>(context: Self, view: &'call mut silk/native_socket.AcceptedView<'call>) -> A ! E ? CallbackRequirements | ContextRequirementsConsumes one owned context while using temporary accepted-connection loans.
listen
pub effect<'static> fn listen(endpoint: Endpoint, options: ListenOptions) -> Listener ! NativeSocketErrorCreates one IPv4 or IPv6 listener and publishes its actual bound endpoint.
listenUnix
pub effect<'life0> fn listenUnix<'life0>(path: &'life0 [u8], options: ListenOptions) -> Listener ! NativeSocketErrorCreates one pathname-Unix listener without unlinking before bind or after close.
accept
pub effect<'life0> fn accept<'life0>(listener: &'life0 mut silk/native_socket.Listener, deadline: silk/option.Option<silk/system_clock.Instant>) -> Accepted ! NativeSocketError ? &mut MonotonicClockAccepts one independently owned connection under an unchanged absolute deadline.
withListener
pub effect<'env> fn withListener<'env, A, E, ?CallbackRequirements>(listener: Listener, callback: for<'call> once fn<'env>(&'call mut silk/native_socket.Listener) -> once Effect<'call; A ! E ? CallbackRequirements>) -> A ! E ? CallbackRequirementsConsumes one listener and lends it through a nonparking structured finalizer.
withAccepted
pub effect<'env> fn withAccepted<'env, A, E, ?CallbackRequirements>(accepted: Accepted, callback: for<'call> once fn<'env>(&'call mut silk/native_socket.AcceptedView<'call>) -> once Effect<'call; A ! E ? CallbackRequirements>) -> A ! E ? CallbackRequirements where CallbackRequirements in Without<CallbackRequirements, &ByteDuplex>Consumes one accepted owner and lends its connection plus borrowed peer metadata.
withAcceptedContext
pub effect<'env> fn withAcceptedContext<A, E, ?CallbackRequirements, ?ContextRequirements, C: 'env, 'env>(accepted: Accepted, context: C) -> A ! E ? CallbackRequirements | ContextRequirements where CallbackRequirements in Without<CallbackRequirements, &ByteDuplex>, ContextRequirements in Without<ContextRequirements, &ByteDuplex>Consumes one compile-time-selected context with temporary accepted-connection loans.
Details
The context is captured by the once-callable protected use and consumed exactly once. Structured success, typed failure, and cancellation close the connection once; close failure never replaces the protected outcome.
connectResolvedOwned
pub effect<'life0> fn connectResolvedOwned<'life0>(endpoints: &'life0 [silk/network_address.Endpoint], options: ConnectOptions, deadline: silk/option.Option<silk/system_clock.Instant>) -> Connection ! NativeSocketError ? &mut MonotonicClockConnects an ordered nonempty numeric endpoint slice and returns one affine provider owner.
connectUnixOwned
pub effect<'life0> fn connectUnixOwned<'life0>(path: &'life0 [u8], options: ConnectOptions, deadline: silk/option.Option<silk/system_clock.Instant>) -> Connection ! NativeSocketError ? &mut MonotonicClockConnects one absolute pathname Unix socket and returns one affine provider owner.
connectResolved
pub effect<'env1> fn connectResolved<'env: 'env1, A, E, ?CallbackRequirements, 'life4: 'env1, 'env1>(endpoints: &'life4 [silk/network_address.Endpoint], options: ConnectOptions, deadline: silk/option.Option<silk/system_clock.Instant>, callback: for<'call> once fn<'env>(&'call mut silk/native_socket.Connection) -> once Effect<'call; A ! E ? CallbackRequirements>) -> A ! E | NativeSocketError ? CallbackRequirements | &mut MonotonicClock where CallbackRequirements in Without<CallbackRequirements, &ByteDuplex>Connects an ordered nonempty numeric endpoint slice and lends the owned provider in one scope.
connectUnix
pub effect<'env1> fn connectUnix<'env: 'env1, A, E, ?CallbackRequirements, 'life4: 'env1, 'env1>(path: &'life4 [u8], options: ConnectOptions, deadline: silk/option.Option<silk/system_clock.Instant>, callback: for<'call> once fn<'env>(&'call mut silk/native_socket.Connection) -> once Effect<'call; A ! E ? CallbackRequirements>) -> A ! E | NativeSocketError ? CallbackRequirements | &mut MonotonicClock where CallbackRequirements in Without<CallbackRequirements, &ByteDuplex>Connects one absolute pathname Unix socket and lends the owned provider in one scope.
Implementation ByteDuplex for Connection
impl ByteDuplex for ConnectionOperation readSomeRaw
readSomeRaw = Connection.readConnectionOperation writeSomeRaw
writeSomeRaw = Connection.writeConnectionOperation flushRaw
flushRaw = Connection.flushConnectionOperation shutdownWriteRaw
shutdownWriteRaw = Connection.shutdownConnectionOperation closeRaw
closeRaw = Connection.closeByteConnection