rspamd_tcp
Rspamd TCP module represents generic TCP asynchronous client available from LUA code. This module hides all complexity: DNS resolving, sessions management, zero-copy text transfers and so on under the hood. It can work in partial or complete modes:
Functions:
Function | Description |
---|---|
rspamd_tcp.connect_sync() |
. |
rspamd_tcp.request({params}) |
This function creates and sends TCP request to the specified host and port,. |
rspamd_tcp.connect_sync({params}) |
Creates new pseudo-synchronous connection to the specific address:port. |
Methods:
Method | Description |
---|---|
tcp:close() |
. |
tcp:add_read(callback, [pattern]) |
. |
tcp:add_write(callback, data) |
. |
tcp:shift_callback() |
. |
tcp:starttls([no_verify]) |
. |
tcp:close() |
. |
read_once() |
. |
eof() |
. |
shutdown() |
. |
write() |
. |
The module rspamd_tcp
defines the following functions.
rspamd_tcp.connect_sync()
Creates pseudo-synchronous TCP connection. Each method of the connection requiring IO, becomes a yielding point, i.e. current thread Lua thread is get suspended and resumes as soon as IO is done
This class represents low-level API, using of “lua_tcp_sync” module is recommended.
Parameters:
No parameters
Returns:
No return
Back to module description.
rspamd_tcp.request({params})
This function creates and sends TCP request to the specified host and port, resolves hostname (if needed) and invokes continuation callback upon data received from the remote peer. This function accepts table of arguments with the following attributes
task
: rspamd task objects (implies pool
, session
, ev_base
and resolver
arguments)ev_base
: event base (if no task specified)resolver
: DNS resolver (no task)session
: events session (no task)host
: IP or name of the peer (required)port
: remote port to usedata
: a table of strings or rspamd_text
objects that contains data piecescallback
: continuation function (required)on_connect
: callback called on connection successtimeout
: floating point value that specifies timeout for IO operations in secondspartial
: boolean flag that specifies that callback should be called on any data portion receivedstop_pattern
: stop reading on finding a certain pattern (e.g. \r\n.\r\n for smtp)shutdown
: half-close socket after writing (boolean: default false)read
: read response after sending request (boolean: default true)upstream
: optional upstream object that would be used to get an addressParameters:
No parameters
Returns:
{boolean}
: true if request has been sentBack to module description.
rspamd_tcp.connect_sync({params})
Creates new pseudo-synchronous connection to the specific address:port
task
: rspamd task objects (implies pool
, session
, ev_base
and resolver
arguments)ev_base
: event base (if no task specified)resolver
: DNS resolver (no task)session
: events session (no task)config
: config (no task)host
: IP or name of the peer (required)port
: remote port to usetimeout
: floating point value that specifies timeout for IO operations in secondsParameters:
No parameters
Returns:
{boolean}
: true if request has been sentBack to module description.
The module rspamd_tcp
defines the following methods.
tcp:close()
Closes TCP connection
Parameters:
No parameters
Returns:
No return
Back to module description.
tcp:add_read(callback, [pattern])
Adds new read event to the tcp connection
Parameters:
callback {function}
: to be called when data is readpattern {string}
: optional stop patternReturns:
No return
Back to module description.
tcp:add_write(callback, data)
Adds new write event to the tcp connection
Parameters:
optional {function}
: callback to be called when data is completely writtendata {table/string/text}
: to send to a remote serverReturns:
No return
Back to module description.
tcp:shift_callback()
Shifts the current callback and go to the next one (if any)
Parameters:
No parameters
Returns:
No return
Back to module description.
tcp:starttls([no_verify])
Starts tls connection
Parameters:
no_verify {boolean}
: used to skip ssl verificationReturns:
No return
Back to module description.
tcp:close()
Closes TCP connection
Parameters:
No parameters
Returns:
No return
Back to module description.
read_once()
Performs one read operation. If syscall returned with EAGAIN/EINT, restarts the operation, so it always returns either data or error.
Parameters:
No parameters
Returns:
No return
Back to module description.
eof()
True if last IO operation ended with EOF, i.e. endpoint closed connection
Parameters:
No parameters
Returns:
No return
Back to module description.
shutdown()
Half-shutdown TCP connection
Parameters:
No parameters
Returns:
No return
Back to module description.
write()
Writes data into the stream. If syscall returned with EAGAIN/EINT restarts the operation. If performs write() until all the passed data is written completely.
Parameters:
No parameters
Returns:
No return
Back to module description.
Back to top.