Browse the docs

silk.net.socket_native.

TCP and Unix socket connections and listeners, as ByteDuplex providers.

When to use#

A Connection provides ByteDuplex, so silk.http.exchange, silk.http.server, and silk.io.buffered_duplex can use it.

Details#

All sockets are nonblocking. When a socket is not ready, the operation waits for the poll interval with MonotonicClock, then tries again. So an idle wait costs about one check for each interval. One deadline covers all attempts of one connect or accept.

A connect tries the endpoints in their order, until one connects or the attempt limit is reached. A flush means that the kernel accepted the bytes, not that the peer got them.

Errors#

NativeSocketError tells the rule, the system error, or the deadline. When all endpoints fail, AttemptsExhausted has the error of the last attempt.

Gotchas#

  • With a deadline of None, a connect or accept can wait forever.

  • Closing a Unix listener does not remove its socket file. Remove it yourself.

  • Scoped functions close the socket on return, error, and cancellation. A trap does not.

  • On Darwin, socket setup is not safe against a fork in another thread.

  • A call fails to compile on targets other than Darwin on aarch64, and Linux with GNU libc on x86_64 or aarch64. The option types still compile.

Examples#

Connect to a local listener#

silk
import silk.io.byte_duplex { ByteDuplex, ByteIoError, ReadTransfer }
import silk.core.effect { Effect }
import silk.system.monotonic_clock { MonotonicClock }
import silk.net.socket_native {
  AcceptedView,
  BoundAddress,
  ConnectOptions,
  Connection,
  ListenOptions,
  Listener,
  NativeSocketError,
  accept,
  connectResolvedOwned,
  listen,
  withAccepted,
}
import silk.net.address { Endpoint, IpAddress, Ipv4Address, Port }
import silk.core.option { Option }
import silk.system.monotonic_clock_native { OsMonotonicClock }
import silk.system.system_clock { Instant }

// Reads one byte from the client and answers with one byte.
effect fn answer<'call>(view: &'call mut AcceptedView<'call>) -> i32
  ! ByteIoError
  ? &mut MonotonicClock {
  let mut input: [u8; 1] = [0]
  match move run ByteDuplex.readSome(&mut input, Option<Instant>.none())
    |> Effect.provideMut<ByteDuplex>(&mut view.connection.*) {
    ReadTransfer.Data { count } => {
      if count != 1 || input[0] != 120 {
        return 1
      }
    }
    ReadTransfer.End => {
      return 1
    }
  }

  // One byte is always written at once, or the call fails.
  let written = run ByteDuplex.writeSome(b"y", Option<Instant>.none())
    |> Effect.provideMut<ByteDuplex>(&mut view.connection.*)
  if written != 1 {
    return 1
  }
  return 0
}

effect fn program() -> i32
  ! NativeSocketError | ByteIoError
  ? &mut MonotonicClock {
  // Port 0 asks the system for a free port.
  let local = Endpoint.make(
    IpAddress.V4 { value: Ipv4Address.fromOctets([127, 0, 0, 1]) },
    Port.fromU16(0)
  )
  let mut listener = run listen(local, ListenOptions.defaults())
  let bound = match Listener.boundAddress(&listener) {
    BoundAddress.Tcp { endpoint } => endpoint
    _ => {
      return 1
    }
  }
  let targets = [bound]
  let mut client = run connectResolvedOwned(
    &targets,
    ConnectOptions.defaults(),
    Option<Instant>.none()
  )
  let sent = run ByteDuplex.writeSome(b"x", Option<Instant>.none())
    |> Effect.provideMut<ByteDuplex>(&mut client)
  if sent != 1 {
    return 1
  }
  let accepted = run accept(&mut listener, Option<Instant>.none())
  run Listener.close(&mut listener)
  let served = run withAccepted<i32, ByteIoError>(move accepted, answer)
  let mut reply: [u8; 1] = [0]
  let read = run ByteDuplex.readSome(&mut reply, Option<Instant>.none())
    |> Effect.provideMut<ByteDuplex>(&mut client)
  run Connection.close(&mut client)
  return match move read {
    ReadTransfer.Data { count } => {
      if served != 0 || count != 1 || reply[0] != 121 {
        return 1
      }
      return 0
    }
    ReadTransfer.End => 1
  }
}

effect fn failed<E>(error: E) -> i32 {
  drop error
  return 1
}

pub fn main() -> i32 {
  let mut clock = OsMonotonicClock.make()
  return run Effect.catchAll(program(), failed) |> Effect.provideMut<MonotonicClock>(&mut clock)
}

Import as NativeSocket with import silk.net.socket_native { NativeSocket }.

Public declarations: 33.

ConnectionPhase#

silk
pub enum ConnectionPhase

The state of a Connection.

Connecting#

silk
Connecting

The connect has not finished.

Open#

silk
Open

Reads and writes are allowed.

WriteClosed#

silk
WriteClosed

The write side is shut down. Reads are still allowed.

Closed#

silk
Closed

The socket is closed.

NativeSocketOperation#

silk
pub enum NativeSocketOperation

The system call that failed.

Socket#

silk
Socket

socket: create the socket.

Configure#

silk
Configure

Set descriptor flags or socket options.

Connect#

silk
Connect

connect.

Bind#

silk
Bind

bind.

Listen#

silk
Listen

listen.

GetSocketName#

silk
GetSocketName

getsockname: read the bound address.

Accept#

silk
Accept

accept.

ConvertAddress#

silk
ConvertAddress

Convert an address that the system returned.

Poll#

silk
Poll

poll: check if the socket is ready.

GetSocketOption#

silk
GetSocketOption

getsockopt: read the error of the socket.

Read#

silk
Read

read.

Write#

silk
Write

write.

ShutdownWrite#

silk
ShutdownWrite

shutdown of the write side.

Close#

silk
Close

close.

Implementation Debug for NativeSocketOperation#

silk
impl Debug for NativeSocketOperation

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the name of the variant, such as Socket.

ListenerPhase#

silk
pub enum ListenerPhase

The state of a Listener.

Open#

silk
Open

The listener accepts clients.

Closed#

silk
Closed

The listener is closed.

ListenOptionsReason#

silk
pub enum ListenOptionsReason

The ListenOptions value that is not valid.

KernelBacklog#

silk
KernelBacklog

The backlog is not 1 through 65535.

PollInterval#

silk
PollInterval

The poll interval is not 1 nanosecond through 1 second.

Implementation Debug for ListenOptionsReason#

silk
impl Debug for ListenOptionsReason

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the name of the variant, such as KernelBacklog.

ListenOptionsError#

silk
pub struct ListenOptionsError

The error of ListenOptions.make.

Field reason#

silk
pub reason: ListenOptionsReason

The value that is not valid.

Field value#

silk
pub value: u64

The value that you gave.

Implementation Debug for ListenOptionsError#

silk
impl Debug for ListenOptionsError

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the fields, as ListenOptionsError { reason: ..., value: ... }.

InvalidBindReason#

silk
pub enum InvalidBindReason

Why a Unix socket path for listenUnix is not valid.

EmptyPath#

silk
EmptyPath

The path is empty.

RelativePath#

silk
RelativePath

The path does not start with /.

NulPath#

silk
NulPath

The path has a NUL byte.

AbstractPath#

silk
AbstractPath

The path is an abstract socket address, which is not supported.

Implementation Debug for InvalidBindReason#

silk
impl Debug for InvalidBindReason

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the name of the variant, such as EmptyPath.

ConnectOptionsReason#

silk
pub enum ConnectOptionsReason

The ConnectOptions value that is not valid.

PollInterval#

silk
PollInterval

The poll interval is not 1 nanosecond through 1 second.

MaxAttempts#

silk
MaxAttempts

The attempt limit is not 1 through 1024.

Implementation Debug for ConnectOptionsReason#

silk
impl Debug for ConnectOptionsReason

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the name of the variant, such as PollInterval.

ConnectOptionsError#

silk
pub struct ConnectOptionsError

The error of ConnectOptions.make.

Field reason#

silk
pub reason: ConnectOptionsReason

The value that is not valid.

Field value#

silk
pub value: u64

The value that you gave.

Implementation Debug for ConnectOptionsError#

silk
impl Debug for ConnectOptionsError

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the fields, as ConnectOptionsError { reason: ..., value: ... }.

InvalidEndpointReason#

silk
pub enum InvalidEndpointReason

Why the endpoints or the Unix socket path of a connect are not valid.

EmptyEndpoints#

silk
EmptyEndpoints

The endpoint list is empty.

TooManyEndpoints#

silk
TooManyEndpoints

There are more endpoints than the attempt limit.

EmptyPath#

silk
EmptyPath

The path is empty.

RelativePath#

silk
RelativePath

The path does not start with /.

NulPath#

silk
NulPath

The path has a NUL byte.

PathTooLong#

silk
PathTooLong

The path is too long for a socket address.

AbstractPath#

silk
AbstractPath

The path is an abstract socket address, which is not supported.

Implementation Debug for InvalidEndpointReason#

silk
impl Debug for InvalidEndpointReason

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the name of the variant, such as EmptyEndpoints.

AttemptFailure#

silk
pub union AttemptFailure

The error of the last connect attempt, in AttemptsExhausted.

ConnectionRefused#

silk
ConnectionRefused

The peer refused the connection.

NetworkUnreachable#

silk
NetworkUnreachable

The network cannot be reached.

AddressUnavailable#

silk
AddressUnavailable

The address is not available.

NativeFailure#

silk
NativeFailure

Another system error.

Field operation#

silk
pub operation: NativeSocketOperation

The system call that failed.

Field errno#

silk
pub errno: i32

The errno value.

Implementation Debug for AttemptFailure#

silk
impl Debug for AttemptFailure

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the name of the variant and its fields, such as ConnectionRefused.

NativeSocketError#

silk
pub union NativeSocketError

The error of a socket operation: the rule that failed, the system error, or the deadline.

AttemptsExhausted#

silk
AttemptsExhausted

All connect attempts failed.

Field attempted#

silk
pub attempted: usize

The number of attempts.

Field last#

silk
pub last: AttemptFailure

The error of the last attempt.

TimeRangeError#

silk
TimeRangeError

The time of the next check does not fit in an Instant.

InvalidEndpoint#

silk
InvalidEndpoint

The endpoints or the socket path of a connect are not valid.

Field reason#

silk
pub reason: InvalidEndpointReason

The rule that failed.

Field offset#

silk
pub offset: usize

The byte position of the problem in the path.

Field limit#

silk
pub limit: usize

The largest allowed value.

InvalidBindAddress#

silk
InvalidBindAddress

The socket path of listenUnix is not valid.

Field reason#

silk
pub reason: InvalidBindReason

The rule that failed.

Field offset#

silk
pub offset: usize

The byte position of the problem in the path.

PathTooLong#

silk
PathTooLong

The socket path is too long for a socket address.

Field length#

silk
pub length: usize

The length of the path.

Field limit#

silk
pub limit: usize

The largest allowed length.

AddressInUse#

silk
AddressInUse

The local address is in use.

InvalidNativeAddress#

silk
InvalidNativeAddress

The system returned an address with a wrong family or length.

Field family#

silk
pub family: i32

The address family, or -1 if the address is too short.

Field length#

silk
pub length: usize

The length of the address.

UnsupportedPeerAddress#

silk
UnsupportedPeerAddress

The peer has an address form that is not supported.

Field family#

silk
pub family: i32

The address family, or -1 if the address is too short.

Field length#

silk
pub length: usize

The length of the address.

FamilyUnsupported#

silk
FamilyUnsupported

The system does not support the address family.

PermissionDenied#

silk
PermissionDenied

The system denied the operation.

ConnectionRefused#

silk
ConnectionRefused

The peer refused the connection.

NetworkUnreachable#

silk
NetworkUnreachable

The network cannot be reached.

AddressUnavailable#

silk
AddressUnavailable

The address is not available.

SystemResources#

silk
SystemResources

The system does not have the resources, such as descriptors.

Timeout#

silk
Timeout

The deadline passed.

Closed#

silk
Closed

The socket is closed.

WriteClosed#

silk
WriteClosed

The write side is shut down.

InvalidTransferCount#

silk
InvalidTransferCount

The system returned a transfer count that is not valid.

Field operation#

silk
pub operation: ByteIoOperation

The operation.

Field count#

silk
pub count: usize

The count that the system returned.

Field limit#

silk
pub limit: usize

The largest valid count.

NativeFailure#

silk
NativeFailure

Another system error.

Field operation#

silk
pub operation: NativeSocketOperation

The system call that failed.

Field errno#

silk
pub errno: i32

The errno value.

Implementation Debug for NativeSocketError#

silk
impl Debug for NativeSocketError

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the name of the variant and its fields, such as AttemptsExhausted { ... }.

NativeSocket#

silk
pub struct NativeSocket

An empty marker type for this module.

ConnectOptions#

silk
pub struct ConnectOptions

The settings of a connect: Nagle, the poll interval, and the attempt limit.

ListenOptions#

silk
pub struct ListenOptions

The settings of a listener: the backlog, address reuse, and the poll interval of accept.

UnixSocketPath#

silk
pub struct UnixSocketPath

A copy of a Unix socket path, at most 108 bytes.

BoundAddress#

silk
pub union BoundAddress

The local address of a Listener.

Tcp#

silk
Tcp

A TCP listener.

Field endpoint#

silk
pub endpoint: Endpoint

The address and port. With port 0 in listen, this is the port that the system chose.

Unix#

silk
Unix

A Unix socket listener.

Field path#

silk
pub path: UnixSocketPath

The socket path.

UnixPeerAddress#

silk
pub union UnixPeerAddress

The address of a Unix socket client.

Unnamed#

silk
Unnamed

The client socket has no path. This is normal for a client.

Pathname#

silk
Pathname

The client socket has a path.

Field path#

silk
pub path: UnixSocketPath

The path.

PeerAddress#

silk
pub union PeerAddress

The address of an accepted client.

Tcp#

silk
Tcp

A TCP client.

Field endpoint#

silk
pub endpoint: Endpoint

The address and port of the client.

Unix#

silk
Unix

A Unix socket client.

Field peer#

silk
pub peer: UnixPeerAddress

The address of the client.

Implementation Copy for ConnectOptionsError#

silk
impl Copy for ConnectOptionsError

Implementation Copy for AttemptFailure#

silk
impl Copy for AttemptFailure

Implementation Copy for NativeSocketError#

silk
impl Copy for NativeSocketError

Implementation Copy for ConnectOptions#

silk
impl Copy for ConnectOptions

Implementation Copy for ListenOptionsError#

silk
impl Copy for ListenOptionsError

Implementation Copy for ListenOptions#

silk
impl Copy for ListenOptions

Implementation Copy for UnixSocketPath#

silk
impl Copy for UnixSocketPath

Implementation Copy for BoundAddress#

silk
impl Copy for BoundAddress

Implementation Copy for UnixPeerAddress#

silk
impl Copy for UnixPeerAddress

Implementation Copy for PeerAddress#

silk
impl Copy for PeerAddress

Implementation ConnectOptions#

silk
impl ConnectOptions

Associated function make#

silk
pub fn make(
    noDelay: bool,
    pollIntervalNanoseconds: u64,
    maxAttempts: usize,
  ) -> Result<ConnectOptions, ConnectOptionsError>

Returns connect options.

Errors#

ConnectOptionsError if pollIntervalNanoseconds is not 1 through 1000000000, or maxAttempts is not 1 through 1024.

Associated function defaults#

silk
pub fn defaults() -> ConnectOptions

Returns the default connect options: Nagle on, a 1 ms poll interval, and 64 attempts.

Method noDelay#

silk
pub fn noDelay(self: &Self) -> bool

Returns whether Nagle is off (TCP_NODELAY).

Method pollInterval#

silk
pub fn pollInterval(self: &Self) -> u64

Returns the poll interval, in nanoseconds.

Method maxAttempts#

silk
pub fn maxAttempts(self: &Self) -> usize

Returns the attempt limit.

Implementation ListenOptions#

silk
impl ListenOptions

Associated function make#

silk
pub fn make(
    kernelBacklog: usize,
    reuseAddress: bool,
    pollIntervalNanoseconds: u64,
  ) -> Result<ListenOptions, ListenOptionsError>

Returns listen options.

Errors#

ListenOptionsError if kernelBacklog is not 1 through 65535, or pollIntervalNanoseconds is not 1 through 1000000000.

Associated function defaults#

silk
pub fn defaults() -> ListenOptions

Returns the default listen options: a backlog of 128, no address reuse, and a 1 ms poll interval.

Method kernelBacklog#

silk
pub fn kernelBacklog(self: &Self) -> usize

Returns the backlog of the kernel.

Method reuseAddress#

silk
pub fn reuseAddress(self: &Self) -> bool

Returns whether the listener sets SO_REUSEADDR.

Method pollInterval#

silk
pub fn pollInterval(self: &Self) -> u64

Returns the poll interval of accept, in nanoseconds.

Implementation UnixSocketPath#

silk
impl UnixSocketPath

Method bytes#

silk
pub fn bytes(self: &Self) -> &[u8]

Returns the path bytes.

Connection#

silk
pub struct Connection

An open socket connection. It provides ByteDuplex, so silk.http.exchange, silk.http.server, and silk.io.buffered_duplex can use it.

Details#

The socket is nonblocking. When it is not ready, an operation waits for the poll interval with MonotonicClock, then tries again. So an idle wait costs about one check for each interval. A flush means that the kernel accepted the bytes, not that the peer got them.

Listener#

silk
pub struct Listener

A listening socket and its local address.

Accepted#

silk
pub struct Accepted

A connection from accept, with the address of the client. Use it with withAccepted.

AcceptedView#

silk
pub struct AcceptedView<'a>

The connection and the client address that withAccepted lends to its callback.

Field connection#

silk
pub connection: &'a mut Connection

The connection. It is valid only in the callback.

Field peer#

silk
pub peer: &'a PeerAddress

The address of the client.

AcceptedContext#

silk
pub interface AcceptedContext<A, E, ?CallbackRequirements, ?ContextRequirements>

A value that serves one accepted connection. See withAcceptedContext.

Details#

Implement it when the code that serves the connection owns state that is moved in, such as a handler. use gets the value one time.

Operation use#

silk
effect<'call> fn use<'call>(
    context: Self,
    view: &'call mut AcceptedView<'call>,
  ) -> A ! E ? CallbackRequirements | ContextRequirements

Serves the connection in view, with context.

Implementation Connection#

silk
impl Connection

Method phase#

silk
pub fn phase(self: &Self) -> ConnectionPhase

Returns the state of the connection.

Method close#

silk
pub effect fn close(self: &mut Self) -> () ! NativeSocketError

Closes the connection. A second call does nothing.

The scoped functions close the connection too, and ignore a close error.

Implementation Listener#

silk
impl Listener

Method phase#

silk
pub fn phase(self: &Self) -> ListenerPhase

Returns the state of the listener.

Method boundAddress#

silk
pub fn boundAddress(self: &Self) -> BoundAddress

Returns the local address of the listener.

Method close#

silk
pub effect fn close(self: &mut Self) -> () ! NativeSocketError

Closes the listener. A second call does nothing. It does not remove a Unix socket file.

Implementation Accepted#

silk
impl Accepted

Method peer#

silk
pub fn peer(self: &Self) -> PeerAddress

Returns the address of the client.

Method connectionPhase#

silk
pub fn connectionPhase(self: &Self) -> ConnectionPhase

Returns the state of the connection.

listen#

silk
pub effect fn listen(endpoint: Endpoint, options: ListenOptions) -> Listener ! NativeSocketError

Makes a TCP listener on endpoint, IPv4 or IPv6.

With port 0, the system chooses a free port. Listener.boundAddress returns it.

Errors#

AddressInUse, PermissionDenied, SystemResources, or another NativeSocketError.

listenUnix#

silk
pub effect fn listenUnix(path: &[u8], options: ListenOptions) -> Listener ! NativeSocketError

Makes a Unix socket listener at path.

It does not remove an old file at path before, or the file after close.

Errors#

InvalidBindAddress or PathTooLong if path is not valid. AddressInUse if a file exists.

accept#

silk
pub effect fn accept(
  listener: &mut Listener,
  deadline: Option<Instant>,
) -> Accepted ! NativeSocketError ? &mut MonotonicClock

Waits for the next client, and returns its connection.

The listener stays open. deadline is absolute, and covers all checks of this call.

Errors#

Timeout if the deadline passes. Closed if the listener is closed.

withListener#

silk
pub effect fn withListener<'env, A, E, ?CallbackRequirements>(
  listener: Listener,
  callback: for<'call> once fn<'env>(
    &'call mut Listener
  ) -> once Effect<'call; A ! E ? CallbackRequirements>,
) -> A ! E ? CallbackRequirements

Lends listener to callback, and closes it after, also on error or cancellation.

withAccepted#

silk
pub effect fn withAccepted<'env, A, E, ?CallbackRequirements>(
  accepted: Accepted,
  callback: for<'call> once fn<'env>(
    &'call mut AcceptedView<'call>
  ) -> once Effect<'call; A ! E ? CallbackRequirements>,
) -> A ! E ? CallbackRequirements
where CallbackRequirements in Without<CallbackRequirements, ByteDuplex>

Lends the connection and the client address of accepted to callback, and closes the connection after, also on error or cancellation.

withAcceptedContext#

silk
pub effect<'env> fn withAcceptedContext<
  A,
  E,
  ?CallbackRequirements,
  ?ContextRequirements,
  C: AcceptedContext<A, E, CallbackRequirements ? ContextRequirements> + 'env,
  'env,
>(
  accepted: Accepted,
  context: C,
) -> A ! E ? CallbackRequirements | ContextRequirements
where CallbackRequirements in Without<CallbackRequirements, ByteDuplex>,
  ContextRequirements in Without<ContextRequirements, ByteDuplex>

Serves accepted with context, and closes the connection after.

Details#

context is used one time. The connection is closed on success, error, and cancellation. A close error never replaces the result.

connectResolvedOwned#

silk
pub effect fn connectResolvedOwned(
  endpoints: &[Endpoint],
  options: ConnectOptions,
  deadline: Option<Instant>,
) -> Connection ! NativeSocketError ? &mut MonotonicClock

Connects to the first of endpoints that accepts, and returns the connection.

Errors#

  • InvalidEndpoint if endpoints is empty or longer than the attempt limit.

  • AttemptsExhausted if no endpoint accepts.

  • Timeout if deadline passes.

connectUnixOwned#

silk
pub effect fn connectUnixOwned(
  path: &[u8],
  options: ConnectOptions,
  deadline: Option<Instant>,
) -> Connection ! NativeSocketError ? &mut MonotonicClock

Connects to the Unix socket at path, and returns the connection.

Errors#

InvalidEndpoint if path is not valid. Timeout if deadline passes.

connectResolved#

silk
pub effect fn connectResolved<'env, A, E, ?CallbackRequirements>(
  endpoints: &[Endpoint],
  options: ConnectOptions,
  deadline: Option<Instant>,
  callback: for<'call> once fn<'env>(
    &'call mut Connection
  ) -> once Effect<'call; A ! E ? CallbackRequirements>,
) -> A ! E | NativeSocketError ? CallbackRequirements | &mut MonotonicClock
where CallbackRequirements in Without<CallbackRequirements, ByteDuplex>

Connects to the first of endpoints that accepts, lends the connection to callback, and closes it after, also on error or cancellation. A trap does not close it.

Errors#

  • The error of callback.

  • InvalidEndpoint if endpoints is empty or longer than the attempt limit.

  • AttemptsExhausted if no endpoint accepts. It has the error of the last attempt.

  • Timeout if deadline passes. One deadline covers all attempts.

Gotchas#

With a deadline of None, the connect can wait forever.

connectUnix#

silk
pub effect fn connectUnix<'env, A, E, ?CallbackRequirements>(
  path: &[u8],
  options: ConnectOptions,
  deadline: Option<Instant>,
  callback: for<'call> once fn<'env>(
    &'call mut Connection
  ) -> once Effect<'call; A ! E ? CallbackRequirements>,
) -> A ! E | NativeSocketError ? CallbackRequirements | &mut MonotonicClock
where CallbackRequirements in Without<CallbackRequirements, ByteDuplex>

Connects to the Unix socket at path, lends the connection to callback, and closes it after, also on error or cancellation. A trap does not close it.

Errors#

  • The error of callback.

  • InvalidEndpoint if path is not valid.

  • Timeout if deadline passes.

Implementation Connection#

silk
impl Connection

Implementation ByteDuplex for Connection#

silk
impl ByteDuplex for Connection

Operation readSomeRaw#

silk
readSomeRaw: Connection.readConnection

Operation writeSomeRaw#

silk
writeSomeRaw: Connection.writeConnection

Operation writeSomeVectoredRaw#

silk
writeSomeVectoredRaw: Connection.writeConnectionVectored

Operation flushRaw#

silk
flushRaw: Connection.flushConnection

Operation shutdownWriteRaw#

silk
shutdownWriteRaw: Connection.shutdownConnection

Operation closeRaw#

silk
closeRaw: Connection.closeByteConnection

Category: Networking.

Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2.

View the source of this page