Utils

Utilities that don’t fall under a specific class

utils.send_all(sock, s)

Attempt to call the send method on the provided, sock retrying on failure or timeout

Parameters:
  • sock (Sender) – The socket to send on

  • s (str) – The string to send

Returns:

the number of bytes sent if not nil

Return type:

integer or nil

Returns:

the last error message encountered if not nil

Return type:

nil or str

Returns:

total bytes sent before failure

Return type:

nil or integer

utils.tcp_socket_source(socket)

Use a luasocket api conforming table as a source function returned will attempt

to call the receive method on the provided socket

Parameters:

socket (Receiver) – A tcp socket

Return type:

SourceFn

utils.next_line(chunk)

Get the first line from a chunk, discarding the new line characters, returning

the line followed by the remainder of the chunk after that line

Parameters:

chunk (str) –

Returns:

If not nil, the line found, if nil no new line character was found

Return type:

str or nil

Return type:

str

utils.extract_len(chunk)

Split the provided chunk at the len

Parameters:

chunk (str) –

Returns:

The first half of the string from the split

Return type:

str

Returns:

The second half of the string from the split (empty if len <= #chunk)

Return type:

str

utils.udp_socket_source(socket)

wrap a luasocket udp socket in a source function, this will handle finding new line

characters. This will call receive on the provided socket repeatedly until a new line is found

Parameters:

socket (Receiver) – a udp socket

Return type:

SourceFn