kayrock v0.1.6 Kayrock.Socket View Source
This module handle all socket related operations.
NOTE this is a copy of KafkaEx.Socket: https://github.com/kafkaex/kafka_ex/blob/master/lib/kafka_ex/socket.ex
It is duplicated here to avoid creating a circular dependency.
Link to this section Summary
Functions
Closes the socket.
Creates a socket.
Returns the information about the socket.
Returns true if the socket is open
Receives data from the socket.
Sends data over the socket.
Set options to the socket.
Link to this section Types
t()
View Source
t() :: %Kayrock.Socket{
socket: :gen_tcp.socket() | :ssl.sslsocket(),
ssl: boolean()
}
t() :: %Kayrock.Socket{ socket: :gen_tcp.socket() | :ssl.sslsocket(), ssl: boolean() }
Link to this section Functions
close(socket)
View Source
close(Kayrock.Socket.t()) :: :ok
close(Kayrock.Socket.t()) :: :ok
Closes the socket.
For more information, see :ssl.close/1
for ssl or :gen_tcp.send/1
for non ssl.
create(host, port, socket_options \\ [], is_ssl \\ false) View Source
Creates a socket.
For more information about the available options, see :ssl.connect/3
for ssl
or :gen_tcp.connect/3
for non ssl.
info(socket)
View Source
info(Kayrock.Socket.t()) :: list() | nil
info(Kayrock.Socket.t()) :: list() | nil
Returns the information about the socket.
For more information, see Port.info
open?(socket)
View Source
open?(Kayrock.Socket.t()) :: boolean()
open?(Kayrock.Socket.t()) :: boolean()
Returns true if the socket is open
recv(socket, length)
View Source
recv(Kayrock.Socket.t(), non_neg_integer()) ::
{:ok, String.t() | binary() | term()} | {:error, any()}
recv(Kayrock.Socket.t(), non_neg_integer()) :: {:ok, String.t() | binary() | term()} | {:error, any()}
Receives data from the socket.
For more information, see :ssl.recv/2
for ssl or :gen_tcp.recv/2
for non ssl.
recv(socket, length, timeout)
View Source
recv(Kayrock.Socket.t(), non_neg_integer(), timeout()) ::
{:ok, String.t() | binary() | term()} | {:error, any()}
recv(Kayrock.Socket.t(), non_neg_integer(), timeout()) :: {:ok, String.t() | binary() | term()} | {:error, any()}
send(socket, data)
View Source
send(Kayrock.Socket.t(), iodata()) :: :ok | {:error, any()}
send(Kayrock.Socket.t(), iodata()) :: :ok | {:error, any()}
Sends data over the socket.
It handles both, SSL and non SSL sockets.
For more information, see :ssl.send/2
for ssl or :gen_tcp.send/2
for non ssl.
setopts(socket, options)
View Source
setopts(Kayrock.Socket.t(), list()) :: :ok | {:error, any()}
setopts(Kayrock.Socket.t(), list()) :: :ok | {:error, any()}
Set options to the socket.
For more information, see :ssl.setopts/2
for ssl or :inet.setopts/2
for non ssl.