View Source ThousandIsland.Socket (Thousand Island v0.6.4)

Encapsulates a client connection's underlying socket, providing a facility to read, write, and otherwise manipulate a connection from a client.

Link to this section Summary

Types

t()

A reference to a socket along with metadata describing how to use it

Functions

Closes the given socket. Note that a socket is automatically closed when the handler process which owns it terminates

Gets the given flags on the socket

Returns statistics about the connection.

Handshakes the underlying socket if it is required (as in the case of SSL sockets, for example).

Returns information in the form of t:ThousandIsland.Transport.socket_info() about the local end of the socket.

Returns information about the protocol negotiated during transport handshaking (if any).

Returns information in the form of t:ThousandIsland.Transport.socket_info() about the remote end of the socket.

Returns available bytes on the given socket. Up to length bytes will be returned (0 can be passed in to get the next 'available' bytes, typically the next packet). If insufficient bytes are available, the function can wait timeout milliseconds for data to arrive.

Returns whether or not this protocol is secure.

Sends the given data (specified as a binary or an IO list) on the given socket.

Sends the contents of the given file based on the provided offset & length

Sets the given flags on the socket

Shuts down the socket in the given direction.

Returns the telemetry span representing the lifetime of this socket

Link to this section Types

@type t() :: %ThousandIsland.Socket{
  read_timeout: timeout(),
  socket: ThousandIsland.Transport.socket(),
  span: ThousandIsland.Telemetry.t(),
  transport_module: module()
}

A reference to a socket along with metadata describing how to use it

Link to this section Functions

@spec close(t()) :: ThousandIsland.Transport.on_close()

Closes the given socket. Note that a socket is automatically closed when the handler process which owns it terminates

Link to this function

getopts(socket, options)

View Source

Gets the given flags on the socket

Errors are usually from :inet.posix(), however, SSL module defines return type as any()

Returns statistics about the connection.

@spec handshake(t()) :: ThousandIsland.Transport.on_handshake()

Handshakes the underlying socket if it is required (as in the case of SSL sockets, for example).

This is normally called internally by ThousandIsland.Handler and does not need to be called by implementations which are based on ThousandIsland.Handler

@spec local_info(t()) :: ThousandIsland.Transport.socket_info()

Returns information in the form of t:ThousandIsland.Transport.socket_info() about the local end of the socket.

Link to this function

negotiated_protocol(socket)

View Source
@spec negotiated_protocol(t()) :: ThousandIsland.Transport.negotiated_protocol_info()

Returns information about the protocol negotiated during transport handshaking (if any).

@spec peer_info(t()) :: ThousandIsland.Transport.socket_info()

Returns information in the form of t:ThousandIsland.Transport.socket_info() about the remote end of the socket.

Link to this function

recv(socket, length \\ 0, timeout \\ nil)

View Source

Returns available bytes on the given socket. Up to length bytes will be returned (0 can be passed in to get the next 'available' bytes, typically the next packet). If insufficient bytes are available, the function can wait timeout milliseconds for data to arrive.

@spec secure?(t()) :: boolean()

Returns whether or not this protocol is secure.

Sends the given data (specified as a binary or an IO list) on the given socket.

Link to this function

sendfile(socket, filename, offset, length)

View Source

Sends the contents of the given file based on the provided offset & length

Link to this function

setopts(socket, options)

View Source

Sets the given flags on the socket

Errors are usually from :inet.posix(), however, SSL module defines return type as any()

Shuts down the socket in the given direction.

@spec telemetry_span(t()) :: ThousandIsland.Telemetry.t()

Returns the telemetry span representing the lifetime of this socket