---@meta socket.serial

--------------------------------------------------------------------------------
-- LuaSocket serial C module
--------------------------------------------------------------------------------

---@type socket_core*
local socket_core = require("socket.core")

---@class socket_serial_client*: socket_core_tcp*
local socket_serial_client = {}

--- Create serial socket.
---@return socket_serial_client*? client serial socket
---@return string? errMsg error message
local function serial() end

--- Send data.
---@param data string data
---@param from? integer starting position
---@param to? integer end position
---@return integer? sent Number of bytes sent
---@return string? errMsg error message
---@return integer? lastIndex last sent position
function socket_serial_client:send(data, from, to) end

--- Receive data.
---@param pattern? '*l'|'*a'|integer receive mode
---@param prefix? string prefix
---@return string? data data
---@return string? errMsg error message
---@return string? partial partial data
function socket_serial_client:receive(pattern, prefix) end

--- Set timeout.
---@param timeout socket_core_timeout Timeout seconds
---@param mode? 'b'|'r'|'s' mode
---@return integer? ok Returns 1 on success
---@return string? errMsg error message
function socket_serial_client:settimeout(timeout, mode) end

--- Close the socket.
---@return integer? ok Returns 1 on success
---@return string? errMsg error message
function socket_serial_client:close() end

--- Get the underlying fd.
---@return integer fd file descriptor
function socket_serial_client:getfd() end

--- Replace underlying fd.
---@param fd integer file descriptor
---@return integer? ok Returns 1 on success
---@return string? errMsg error message
function socket_serial_client:setfd(fd) end

--- Check whether there is unread data in the buffer.
---@return boolean dirty Is there any unread data?
function socket_serial_client:dirty() end

--- Get transfer statistics.
---@return integer received Number of bytes received
---@return integer sent Number of bytes sent
---@return number age seconds after creation
function socket_serial_client:getstats() end

--- Set transfer statistics.
---@param received? integer Number of bytes received
---@param sent? integer Number of bytes sent
---@param age? number seconds after creation
---@return integer? ok Returns 1 on success
function socket_serial_client:setstats(received, sent, age) end

return serial
