View Source Soyaki.Socket (soyaki v1.0.1)

A struct that keeps track of options, and the underlying socket pid. Provides functionality to link/unlink, send, receive, and close. Banged versions might be a thing one day.

Link to this section Summary

Types

t()

A reference to a socket along with some info.

Functions

Subscribes the calling process to the next packet to arrive in the socket. Can send one of 3 messages

Returns a specification to start this module under a supervisor.

Closes the socket. If specified, a final packet would be sent. Bold of you to expect for it to arrive, though.

Links a socket to the calling process.

Listens for a packet to arrive in the socket. Blocks the calling process.

Sends a udp packet to the connected ip and port.

Uninks a socket from the calling process.

Link to this section Types

@type options() :: []
@type t() :: %Soyaki.Socket{
  read_timeout: term(),
  socket_options: [],
  socket_pid: pid()
}

A reference to a socket along with some info.

Link to this section Functions

Link to this function

async_recv(map, timeout \\ nil)

View Source
@spec async_recv(t(), nil | integer()) :: :ok

Subscribes the calling process to the next packet to arrive in the socket. Can send one of 3 messages:

:timeout
{:udp_closed, nil}
{:udp, nil, packet}

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

close(map, reason \\ nil, lastpacket \\ nil)

View Source
@spec close(t(), atom(), nil | binary()) :: :ok

Closes the socket. If specified, a final packet would be sent. Bold of you to expect for it to arrive, though.

@spec link(t()) :: :ok

Links a socket to the calling process.

Link to this function

recv(map, timeout \\ nil)

View Source
@spec recv(t(), nil | integer()) :: {:ok, binary()} | {:error, :timeout}

Listens for a packet to arrive in the socket. Blocks the calling process.

Sends a udp packet to the connected ip and port.

@spec unlink(t()) :: :ok

Uninks a socket from the calling process.