I/O Read, Write and Close

Application can read from or write to a socket, or close the socket.

Libre_IoClose

Libre_IoClose(fd)

Closes the socket handle.

Parameters:

  • fd - Integer, the socket handle.

Note: Closing the socket automatically unsubscribes the related I/O events on the socket. In another word, Libre_ClearWaitIo(fd) will automatically be called.

Libre_IoRead

Libre_IoRead(fd, buf, from, len)

Connects to a port on a local ethernet device discovered by Liberty IoT Hub.

Parameters:

  • fd - Integer, the socket handle.
  • buf - A buffer object, see buffer for details.
  • from - Integer, the start position of buffer to save the result. Note: the minimum position is 1 instead of 0.
  • len - Integer, the length to read from socket.

Returns:

  • n - The bytes read.
  • err - Error message or nil if no error.

Note: If there is an error the socket will automatically be closed.

Libre_IoWrite

Libre_IoWrite(fd, buf, from, len)

Connects to a port on a local ethernet device discovered by Liberty IoT Hub.

Parameters:

  • fd - Integer, the socket handle.
  • buf - A buffer object, see buffer for details.
  • from - Integer, the start position of buffer to save the result. Note: the minimum position is 1 instead of 0.
  • len - Integer, the length to write to socket.

Returns:

  • n - The bytes written.
  • err - Error message or nil if no error.

Note: If there is an error the socket will automatically be closed.