I/O setup and related functions

## Typedefs

typedef int(* | write_to_socket_fn) (struct lightify_ctx *ctx, unsigned char *msg, size_t size)
typedef int(* | read_from_socket_fn) (struct lightify_ctx *ctx, unsigned char *msg, size_t size)

## Functions

int | lightify_skt_setfd (struct lightify_ctx *ctx, int socket)
int | lightify_skt_getfd (struct lightify_ctx *ctx)
int | lightify_skt_setiotimeout (struct lightify_ctx *ctx, struct timeval tv)
struct timeval | lightify_skt_getiotimeout (struct lightify_ctx *ctx)

## Detailed Description

## Typedef Documentation

typedef int(* read_from_socket_fn) (struct lightify_ctx *ctx, unsigned char *msg, size_t size)

callback to roll your own I/O: Reading

if the default is overriden, this function is called whenever the library wants to read from the gateway.

Parameters

  ctx | library context
  msg | where to place the received bytes
  size | how much to read. Do not read more than this!

Returns
  return a negative number (preferable from errno.h) on error, otherwise return the actually amount of bytes read.

See also
  Default implementation is read_from_socket in module socket.h
  lightify_set_socket_fn

Definition at line 168 of file liblightify.h.

typedef int(* write_to_socket_fn) (struct lightify_ctx *ctx, unsigned char *msg, size_t size)

callback to roll your own I/O: Writing

if the default function is overriden, this function is called whenever the library wants to talk to the gateway.

Parameters

  ctx | library context
  msg | what to write
  size | how much to write

Returns
  return a negative number (preferable from errno.h) on error, otherwise return the actually amount of bytes written.

See also
  Default implementation is write_to_socket in module socket.h
  lightify_set_socket_fn

Definition at line 150 of file liblightify.h.

## Function Documentation

int lightify_skt_getfd | ( | struct lightify_ctx * | ctx | ) |

get the socket fd to be used for communication.

Parameters

  ctx |

Returns
  socket, or -1 if no socket was set

See also
  read_from_socket lightify_set_socket_fn

Definition at line 210 of file socket.c.

struct timeval lightify_skt_getiotimeout | ( | struct lightify_ctx * | ctx | ) |

Get the current timeout set.

Parameters

  ctx |

Returns
  timeval. if ctx was NULL, returns a timeval set to zero.

Note
  used by the default I/O implementation, write_to_socket() and read_from_socket(), see there.

Definition at line 221 of file socket.c.

int lightify_skt_setfd | ( | struct lightify_ctx * | ctx,
|  | int | socket
| ) |  |

set the socket fd to be used for communication.

When using the default I/O functions read_from_socket() and write_to_socket(), the lib expects a ready-to-use socket supplied by the application. It is safe to use non-blocking I/O.

To unset the fd, pass -1.

Parameters

  ctx | contect
  socket | file descriptor to be used or -1 to unset

Returns
  0 on success, negative on error

See also
  lightify_set_socket_fn lightify_skt_getfd

Definition at line 204 of file socket.c.

int lightify_skt_setiotimeout | ( | struct lightify_ctx * | ctx,
|  | struct timeval | tv
| ) |  |

set timeout to be used for socket communication.

Parameters

  ctx | library context
  tv | timout to be used

Returns
  0 on success, negative on errors.

Note
  the timeout is only used if the socket is setup using O_NONBLOCK.
  used by the default I/O implementation, write_to_socket() and read_from_socket(), see there.

See also
  write_to_socket() read_from_socket()

Definition at line 215 of file socket.c.