Loading...
Searching...
No Matches
osmo_io_ops Struct Reference
Osmocom I/O interface

I/O operations (call-back functions) related to an osmo_io_fd. More...

`#include <osmo_io.h>`

## Data Fields

struct { |
void(* read_cb )(struct osmo_io_fd *iofd, int res, struct msgb *msg) |
| completion call-back function when something was read from fd. More...
void(* write_cb )(struct osmo_io_fd *iofd, int res, struct msgb *msg) |
| completion call-back function when write issued via osmo_iofd_write_msgb() has completed on fd. More...
int(* segmentation_cb )(struct msgb *msg) |
| optional call-back function to segment the data at message boundaries. More...
int(* segmentation_cb2 )(struct osmo_io_fd *iofd, struct msgb *msg) |
| optional call-back function to segment the data at message boundaries. More...
}; |
struct { |
void(* recvfrom_cb )(struct osmo_io_fd *iofd, int res, struct msgb *msg, const struct osmo_sockaddr *saddr) |
| completion call-back function when recvfrom(2) has completed. More...
void(* sendto_cb )(struct osmo_io_fd *iofd, int res, struct msgb *msg, const struct osmo_sockaddr *daddr) |
| completion call-back function when sendto() issued via osmo_iofd_sendto_msgb() has completed on fd. More...
}; |
struct { |
void(* recvmsg_cb )(struct osmo_io_fd *iofd, int res, struct msgb *msg, const struct msghdr *msgh) |
| completion call-back function when recvmsg(2) has completed. More...
void(* sendmsg_cb )(struct osmo_io_fd *iofd, int res, struct msgb *msg) |
| completion call-back function when sendmsg() issued via osmo_iofd_sendmsg_msgb() has completed on fd. More...
}; |

## Detailed Description

I/O operations (call-back functions) related to an osmo_io_fd.

## Field Documentation

## [struct]

struct { ... } osmo_io_ops

## [struct]

struct { ... } osmo_io_ops

## [struct]

struct { ... } osmo_io_ops

## read_cb

void(* osmo_io_ops::read_cb) (struct osmo_io_fd *iofd, int res, struct msgb *msg)

completion call-back function when something was read from fd.

Only valid in OSMO_IO_FD_MODE_READ_WRITE.

Parameters

  [in] | iofd | osmo_io_fd for which read() has completed.
  [in] | res | return value of the read() call, or -errno in case of error.
  [in] | msg | message buffer containing the read data. Ownership is transferred to the call-back, and it must make sure to msgb_free() it eventually!

NOTE: If segmentation_cb is in use, the bytes read in res value may be different than those provided in the msg parameter!

Referenced by _call_read_cb(), check_mode_callback_compat(), osmo_iofd_register(), and osmo_iofd_set_ioops().

## recvfrom_cb

void(* osmo_io_ops::recvfrom_cb) (struct osmo_io_fd *iofd, int res, struct msgb *msg, const struct osmo_sockaddr *saddr)

completion call-back function when recvfrom(2) has completed.

Only valid in OSMO_IO_FD_MODE_RECVFROM_SENDTO.

Parameters

  [in] | iofd | osmo_io_fd for which recvfrom() has completed.
  [in] | res | return value of the recvfrom() call, or -errno in case of error.
  [in] | msg | message buffer containing the read data. Ownership is transferred to the call-back, and it must make sure to msgb_free() it eventually!
  [in] | saddr | socket-address of sender from which data was received.

Referenced by check_mode_callback_compat(), iofd_handle_recv(), osmo_iofd_register(), and osmo_iofd_set_ioops().

## recvmsg_cb

void(* osmo_io_ops::recvmsg_cb) (struct osmo_io_fd *iofd, int res, struct msgb *msg, const struct msghdr *msgh)

completion call-back function when recvmsg(2) has completed.

Only valid in OSMO_IO_FD_MODE_RECVMSG_SENDMSG.

Parameters

  [in] | iofd | osmo_io_fd for which recvmsg() has completed.
  [in] | res | return value of the recvmsg() call, or -errno in case of error.
  [in] | msg | message buffer containing the read data. Ownership is transferred to the call-back, and it must make sure to msgb_free() it eventually!
  [in] | msgh | msghdr containing metadata related to the recvmsg call. Only valid until call-back ends.

Referenced by check_mode_callback_compat(), iofd_handle_recv(), osmo_iofd_register(), and osmo_iofd_set_ioops().

## segmentation_cb

int(* osmo_io_ops::segmentation_cb) (struct msgb *msg)

optional call-back function to segment the data at message boundaries.

Parameters

  [in] | msg | message buffer whose data is to be segmented

Returns
  See full function description.

This is useful when message boundaries are to be preserved over a SOCK_STREAM transport socket like TCP. Can be NULL for any application not requiring de-segmentation of received data.

The call-back needs to return the size of the next message. If it returns -EAGAIN or a value larger than msgb_length() (message is incomplete) osmo_io will wait for more data to be read. Other negative values cause the msg to be discarded. If a full message was received (segmentation_cb() returns a value <= msgb_length()) the msgb will be trimmed to size by osmo_io and forwarded to the read call-back. Any parsing done to the msgb by segmentation_cb() will be preserved for the read_cb() (e.g. setting lxh or msgb->cb).

Only one (or none) of both segmentation_cb and segmentation_cb2 shall be set. Having both set will be considered an error during iofd setup.

Referenced by check_mode_callback_compat(), and iofd_handle_segmentation().

## segmentation_cb2

int(* osmo_io_ops::segmentation_cb2) (struct osmo_io_fd *iofd, struct msgb *msg)

optional call-back function to segment the data at message boundaries.

Parameters

  [in] | iofd | handling msg
  [in] | msg | message buffer whose data is to be segmented

Returns
  See full function description.

Same as segmentation_cb above, with an extra parameter to have access to the iofd and its related functionalities (eg data pointer). This is useful for users requiring to store global state or access external objects while segmenting.

The provided iofd shall not be freed by the user during the callback.

Only one (or none) of both segmentation_cb and segmentation_cb2 shall be set. Having both set will be considered an error during iofd setup.

Referenced by check_mode_callback_compat(), and iofd_handle_segmentation().

## sendmsg_cb

void(* osmo_io_ops::sendmsg_cb) (struct osmo_io_fd *iofd, int res, struct msgb *msg)

completion call-back function when sendmsg() issued via osmo_iofd_sendmsg_msgb() has completed on fd.

Only valid in Only valid in OSMO_IO_FD_MODE_RECVMSG_SENDMSG.

Parameters

  [in] | iofd | on which a sendmsg() has completed.
  [in] | res | return value of the sendmsg() call, or -errno in case of error.
  [in] | msg | message buffer whose write has completed. Ownership is not transferred to the call-back; it is automatically freed after the call-back terminates!

Referenced by check_mode_callback_compat(), iofd_poll_ofd_cb_recvmsg_sendmsg(), and iofd_send_completion_cb().

## sendto_cb

void(* osmo_io_ops::sendto_cb) (struct osmo_io_fd *iofd, int res, struct msgb *msg, const struct osmo_sockaddr *daddr)

completion call-back function when sendto() issued via osmo_iofd_sendto_msgb() has completed on fd.

Only valid in OSMO_IO_FD_MODE_RECVFROM_SENDTO.

Parameters

  [in] | iofd | on which a sendto() has completed.
  [in] | res | return value of the sendto() call, or -errno in case of error.
  [in] | msg | message buffer whose write has completed. Ownership is not transferred to the call-back; it is automatically freed after the call-back terminates!
  [in] | daddr | socket-address of destination to which data was sent.

Referenced by check_mode_callback_compat(), iofd_poll_ofd_cb_recvmsg_sendmsg(), and iofd_send_completion_cb().

## write_cb

void(* osmo_io_ops::write_cb) (struct osmo_io_fd *iofd, int res, struct msgb *msg)

completion call-back function when write issued via osmo_iofd_write_msgb() has completed on fd.

Only valid in OSMO_IO_FD_MODE_READ_WRITE.

Parameters

  [in] | iofd | on which a write() has completed.
  [in] | res | return value of the write() call, or -errno in case of error.
  [in] | msg | message buffer whose write has completed. Ownership is not transferred to the call-back; it is automatically freed after the call-back terminates!

Referenced by check_mode_callback_compat(), iofd_poll_ofd_cb_recvmsg_sendmsg(), and iofd_send_completion_cb().

The documentation for this struct was generated from the following file:

- include/osmocom/core/osmo_io.h