WasiTcpSocket Class

A TCP socket of a WasiNetwork.

public abstract class WasiTcpSocket : IDisposable

Remarks

The options have default implementations that keep the values, without effect on the socket.

Implements

Constructors

NameDescription
WasiTcpSocket()

WasiTcpSocket()

WasiNetwork.cs
protected WasiTcpSocket()

No documentation is available.

Properties

NameDescription
HopLimitGets or sets the time to live of the packets (IP_TTL, IPV6_UNICAST_HOPS).
KeepAliveGets or sets whether the socket sends keep-alive packets (SO_KEEPALIVE).
KeepAliveCountGets or sets the number of keep-alive packets without answer before the connection is closed (TCP_KEEPCNT).
KeepAliveIdleTimeGets or sets the time without data before the first keep-alive packet (TCP_KEEPIDLE).
KeepAliveIntervalGets or sets the time between the keep-alive packets (TCP_KEEPINTVL).
ListenBacklogGets or sets the size of the queue of the pending connections.
LocalEndPointGets the local address of the socket, or null when it is not bound.
ReceiveBufferSizeGets or sets the size of the receive buffer (SO_RCVBUF).
RemoteEndPointGets the remote address of a connected socket, or null.
SendBufferSizeGets or sets the size of the send buffer (SO_SNDBUF).

Gets or sets the time to live of the packets (IP_TTL, IPV6_UNICAST_HOPS).

public virtual int HopLimit { get; set; }

Property value

int

Gets or sets whether the socket sends keep-alive packets (SO_KEEPALIVE).

public virtual bool KeepAlive { get; set; }

Property value

bool

KeepAliveCount

WasiNetwork.cs

Gets or sets the number of keep-alive packets without answer before the connection is closed (TCP_KEEPCNT).

public virtual int KeepAliveCount { get; set; }

Property value

int

KeepAliveIdleTime

WasiNetwork.cs

Gets or sets the time without data before the first keep-alive packet (TCP_KEEPIDLE).

public virtual TimeSpan KeepAliveIdleTime { get; set; }

Property value

TimeSpan

KeepAliveInterval

WasiNetwork.cs

Gets or sets the time between the keep-alive packets (TCP_KEEPINTVL).

public virtual TimeSpan KeepAliveInterval { get; set; }

Property value

TimeSpan

ListenBacklog

WasiNetwork.cs

Gets or sets the size of the queue of the pending connections.

public virtual int ListenBacklog { get; set; }

Property value

int

LocalEndPoint

Gets the local address of the socket, or null when it is not bound.

public abstract IPEndPoint? LocalEndPoint { get; }

Property value

IPEndPoint?

ReceiveBufferSize

WasiNetwork.cs

Gets or sets the size of the receive buffer (SO_RCVBUF).

public virtual int ReceiveBufferSize { get; set; }

Property value

int

RemoteEndPoint

Gets the remote address of a connected socket, or null.

public abstract IPEndPoint? RemoteEndPoint { get; }

Property value

IPEndPoint?

SendBufferSize

WasiNetwork.cs

Gets or sets the size of the send buffer (SO_SNDBUF).

public virtual int SendBufferSize { get; set; }

Property value

int

Methods

NameDescription
AcceptAsync(CancellationToken)Accepts a connection of a listening socket.
Bind(IPEndPoint)Binds the socket to a local address. The port 0 is a free port.
ConnectAsync(IPEndPoint, CancellationToken)Connects the socket to a remote address, after binding it to a free port when it is not bound.
Dispose()Closes the socket.
Dispose(bool)Closes the socket.
Listen(int)Starts listening for connections. The socket is bound.
ReceiveAsync(Memory<byte>, CancellationToken)Receives data from the peer of a connected socket.
SendAsync(ReadOnlyMemory<byte>, CancellationToken)Sends data to the peer of a connected socket.
ShutdownSend()Shuts down the sending side of the connection: the peer receives the end of the data.

AcceptAsync(CancellationToken)

Accepts a connection of a listening socket.

public abstract ValueTask<WasiTcpSocket> AcceptAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken
The token that is cancelled when the component drops the stream of the connections.

Returns

ValueTask<WasiTcpSocket> The connected socket.

Exceptions

SocketException
The connection failed.

Bind(IPEndPoint)

Binds the socket to a local address. The port 0 is a free port.

public abstract void Bind(IPEndPoint localEndPoint)

Parameters

localEndPoint IPEndPoint
A unicast address of the family of the socket, or the unspecified address.

Exceptions

SocketException
The address is not available or is in use.

ConnectAsync(IPEndPoint, CancellationToken)

Connects the socket to a remote address, after binding it to a free port when it is not bound.

public abstract ValueTask ConnectAsync(IPEndPoint remoteEndPoint, CancellationToken cancellationToken)

Parameters

remoteEndPoint IPEndPoint
A unicast address of the family of the socket, with a port.
cancellationToken CancellationToken
The token that is cancelled when the component cancels the connection.

Returns

ValueTask

Exceptions

SocketException
The connection failed.

Dispose overloads

Closes the socket.

public void Dispose()

Dispose(bool)

Closes the socket.

protected abstract void Dispose(bool disposing)
Parameters
disposing bool
Whether the method is called by WasiTcpSocket.Dispose.

Listen(int)

Starts listening for connections. The socket is bound.

public abstract void Listen(int backlog)

Parameters

backlog int
The size of the queue of the pending connections.

Exceptions

SocketException
The socket cannot listen.

ReceiveAsync(Memory<byte>, CancellationToken)

Receives data from the peer of a connected socket.

public abstract ValueTask<int> ReceiveAsync(Memory<byte> buffer, CancellationToken cancellationToken)

Parameters

buffer Memory<byte>
The buffer that receives the data.
cancellationToken CancellationToken
The token that is cancelled when the component drops the stream of the data.

Returns

ValueTask<int> The number of bytes received, or 0 when the peer shut down its side of the connection.

Exceptions

SocketException
The connection is reset.

SendAsync(ReadOnlyMemory<byte>, CancellationToken)

Sends data to the peer of a connected socket.

public abstract ValueTask SendAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken)

Parameters

buffer ReadOnlyMemory<byte>
The data.
cancellationToken CancellationToken
The token that is cancelled when the component cancels the copy.

Returns

ValueTask

Exceptions

SocketException
The connection is broken or reset.

ShutdownSend()

Shuts down the sending side of the connection: the peer receives the end of the data.

public abstract void ShutdownSend()