ber_sockbuf_add_io - Linux


Overview

ber_sockbuf_add_io adds an I/O substream to a BerSockBuf that is registered with the asynchronous I/O library.

Syntax

void ber_sockbuf_add_io(BerSockBuf *sbuf, ...)

Options/Flags

  • None

Examples

/* Create a socket. */
int sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0)
    exit(1);

/* Create a BerSockBuf based on the socket. */
BerSockBuf *sbuf = ber_sockbuf_new(sock);
if (sbuf == NULL)
    exit(1);

/* Add the socket to the asynchronous I/O library. */
ber_sockbuf_add_io(sbuf, &fd, BER_ANONYMOUS, BER_RDONLY, sbuf, callback);

Common Issues

  • Make sure that the socket is not already registered with the asynchronous I/O library.
  • Make sure that the callback function is defined.

Integration

This command can be used with other commands to create a network server. For example, the following command creates a server that listens on port 8080:

./myserver -p 8080

Related Commands

  • ber_sockbuf_new
  • ber_sockbuf_get_fd
  • ber_sockbuf_del_io