Struct smoltcp::socket::TcpSocket [] [src]

pub struct TcpSocket<'a> { /* fields omitted */ }

A Transmission Control Protocol socket.

A TCP socket may passively listen for connections or actively connect to another endpoint. Note that, for listening sockets, there is no "backlog"; to be able to simultaneously accept several connections, as many sockets must be allocated, or any new connection attempts will be reset.

Methods

impl<'a> TcpSocket<'a>
[src]

[src]

Create a socket using the given buffers.

[src]

Return the debug identifier.

[src]

Set the debug identifier.

The debug identifier is a number printed in socket trace messages. It could as well be used by the user code.

[src]

Return the timeout duration.

See also the set_timeout method.

[src]

Set the timeout duration.

A socket with a timeout duration set will abort the connection if either of the following occurs:

  • After a connect call, the remote endpoint does not respond within the specified duration;
  • After establishing a connection, there is data in the transmit buffer and the remote endpoint exceeds the specified duration between any two packets it sends;
  • After enabling keep-alive, the remote endpoint exceeds the specified duration between any two packets it sends.

[src]

Return the keep-alive interval.

See also the set_keep_alive method.

[src]

Set the keep-alive interval.

An idle socket with a keep-alive interval set will transmit a "challenge ACK" packet every time it receives no communication during that interval. As a result, three things may happen:

  • The remote endpoint is fine and answers with an ACK packet.
  • The remote endpoint has rebooted and answers with an RST packet.
  • The remote endpoint has crashed and does not answer.

The keep-alive functionality together with the timeout functionality allows to react to these error conditions.

[src]

Return the local endpoint.

[src]

Return the remote endpoint.

[src]

Return the connection state, in terms of the TCP state machine.

[src]

Start listening on the given endpoint.

This function returns Err(Error::Illegal) if the socket was already open (see is_open), and Err(Error::Unaddressable) if the port in the given endpoint is zero.

[src]

Connect to a given endpoint.

The local port must be provided explicitly. Assuming fn get_ephemeral_port() -> u16 allocates a port between 49152 and 65535, a connection may be established as follows:

Be careful when using this code, it's not being tested!
socket.connect((IpAddress::v4(10, 0, 0, 1), 80), get_ephemeral_port())

The local address may optionally be provided.

This function returns an error if the socket was open; see is_open. It also returns an error if the local or remote port is zero, or if the remote address is unspecified.

[src]

Close the transmit half of the full-duplex connection.

Note that there is no corresponding function for the receive half of the full-duplex connection; only the remote end can close it. If you no longer wish to receive any data and would like to reuse the socket right away, use abort.

[src]

Aborts the connection, if any.

This function instantly closes the socket. One reset packet will be sent to the remote endpoint.

In terms of the TCP state machine, the socket may be in any state and is moved to the CLOSED state.

[src]

Return whether the socket is passively listening for incoming connections.

In terms of the TCP state machine, the socket must be in the LISTEN state.

[src]

Return whether the socket is open.

This function returns true if the socket will process incoming or dispatch outgoing packets. Note that this does not mean that it is possible to send or receive data through the socket; for that, use can_send or can_recv.

In terms of the TCP state machine, the socket must be in the CLOSED or TIME-WAIT state.

[src]

Return whether a connection is active.

This function returns true if the socket is actively exchanging packets with a remote endpoint. Note that this does not mean that it is possible to send or receive data through the socket; for that, use can_send or can_recv.

If a connection is established, abort will send a reset to the remote endpoint.

In terms of the TCP state machine, the socket must be in the CLOSED, TIME-WAIT, or LISTEN state.

[src]

Return whether the transmit half of the full-duplex connection is open.

This function returns true if it's possible to send data and have it arrive to the remote endpoint. However, it does not make any guarantees about the state of the transmit buffer, and even if it returns true, send may not be able to enqueue any octets.

In terms of the TCP state machine, the socket must be in the ESTABLISHED or CLOSE-WAIT state.

[src]

Return whether the receive half of the full-duplex connection is open.

This function returns true if it's possible to receive data from the remote endpoint. It will return true while there is data in the receive buffer, and if there isn't, as long as the remote endpoint has not closed the connection.

In terms of the TCP state machine, the socket must be in the ESTABLISHED, FIN-WAIT-1, or FIN-WAIT-2 state, or have data in the receive buffer instead.

[src]

Check whether the transmit half of the full-duplex connection is open (see may_send, and the transmit buffer is not full.

[src]

Check whether the receive half of the full-duplex connection buffer is open (see may_recv, and the receive buffer is not empty.

[src]

Enqueue a sequence of octets to be sent, and return a pointer to it.

This function may return a slice smaller than the requested size in case there is not enough contiguous free space in the transmit buffer, down to an empty slice.

This function returns `Err(Error::Illegal) if the transmit half of the connection is not open; see may_send.

[src]

Enqueue a sequence of octets to be sent, and fill it from a slice.

This function returns the amount of bytes actually enqueued, which is limited by the amount of free space in the transmit buffer; down to zero.

See also send.

[src]

Dequeue a sequence of received octets, and return a pointer to it.

This function may return a slice smaller than the requested size in case there are not enough octets queued in the receive buffer, down to an empty slice.

This function returns `Err(Error::Illegal) if the receive half of the connection is not open; see may_recv.

[src]

Dequeue a sequence of received octets, and fill a slice from it.

This function returns the amount of bytes actually dequeued, which is limited by the amount of free space in the transmit buffer; down to zero.

See also recv.

[src]

Peek at a sequence of received octets without removing them from the receive buffer, and return a pointer to it.

This function otherwise behaves identically to recv.

[src]

Peek at a sequence of received octets without removing them from the receive buffer, and fill a slice from it.

This function otherwise behaves identically to recv_slice.

[src]

Return the amount of octets queued in the transmit buffer.

Note that the Berkeley sockets interface does not have an equivalent of this API.

[src]

Return the amount of octets queued in the receive buffer.

Note that the Berkeley sockets interface does not have an equivalent of this API.

Trait Implementations

impl<'a> Debug for TcpSocket<'a>
[src]

[src]

Formats the value using the given formatter.

impl<'a> Write for TcpSocket<'a>
[src]

[src]

Writes a slice of bytes into this writer, returning whether the write succeeded. Read more

1.1.0
[src]

Writes a [char] into this writer, returning whether the write succeeded. Read more

1.0.0
[src]

Glue for usage of the [write!] macro with implementors of this trait. Read more