ble_gatt_client
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
io-mainloop.c File Reference

set of function to manage io part of the mainloop feature More...

#include <unistd.h>
#include <errno.h>
#include <sys/socket.h>
#include "mainloop.h"
#include "util.h"
#include "io.h"

Go to the source code of this file.

Data Structures

struct  io
 data structure to manage io More...
 

Functions

static struct ioio_ref (struct io *io)
 
static void io_unref (struct io *io)
 
static void io_cleanup (void *user_data)
 
static void io_callback (int fd, uint32_t events, void *user_data)
 
struct ioio_new (int fd)
 
void io_destroy (struct io *io)
 
int io_get_fd (struct io *io)
 
bool io_set_close_on_destroy (struct io *io, bool do_close)
 
bool io_set_read_handler (struct io *io, io_callback_func_t callback, void *user_data, io_destroy_func_t destroy)
 
bool io_set_write_handler (struct io *io, io_callback_func_t callback, void *user_data, io_destroy_func_t destroy)
 
bool io_set_disconnect_handler (struct io *io, io_callback_func_t callback, void *user_data, io_destroy_func_t destroy)
 
ssize_t io_send (struct io *io, const struct iovec *iov, int iovcnt)
 
bool io_shutdown (struct io *io)
 

Detailed Description

set of function to manage io part of the mainloop feature

See also
mainloop.c
Author
Gilbert Brault

Definition in file io-mainloop.c.

Function Documentation

static void io_callback ( int  fd,
uint32_t  events,
void *  user_data 
)
static

depending on events epoll event and read, write or disconnect prepare for the appropriate call back calling mainloop_modify_fd

epoll event value (some 'ored' combination allowed) EPOLLRDHUP | EPOLLHUP | EPOLLERR | EPOLLIN | EPOLLOUT )

Parameters
fdfile descriptor data structure (can be socket)
eventsepoll event
user_datapointer to io data structure

Definition at line 128 of file io-mainloop.c.

References io::disconnect_callback, io::disconnect_data, io::disconnect_destroy, io::events, io::fd, io_ref(), io_unref(), mainloop_modify_fd(), mainloop_remove_fd(), io::read_callback, io::read_data, io::read_destroy, io::write_callback, io::write_data, and io::write_destroy.

Referenced by io_new().

static void io_cleanup ( void *  user_data)
static

io data structure house keeping

Parameters
user_datapointer to io data structure

Definition at line 100 of file io-mainloop.c.

References io::close_on_destroy, io::disconnect_data, io::disconnect_destroy, io::fd, io::read_data, io::read_destroy, io::write_data, and io::write_destroy.

Referenced by io_new().

void io_destroy ( struct io io)

remove the fd from the 'mainloop' and reset all io call back, unref the io data structure

Parameters
iopointer to the io data structure

Definition at line 226 of file io-mainloop.c.

References io::disconnect_callback, io::fd, io_unref(), mainloop_remove_fd(), io::read_callback, and io::write_callback.

Referenced by bt_att_free(), and disconnect_cb().

int io_get_fd ( struct io io)

return the fd (file descriptor, can be a socket) attached to the io data structure

Parameters
iopointer to io data structure
Returns

Definition at line 246 of file io-mainloop.c.

References io::fd.

struct io* io_new ( int  fd)

create a new io data structure

Parameters
fdfile descriptor (includes socket)
Returns
NULL if error or io data structure

Definition at line 197 of file io-mainloop.c.

References io::close_on_destroy, io::events, io::fd, io_callback(), io_cleanup(), io_ref(), mainloop_add_fd(), and new0.

Referenced by bt_att_new().

static struct io* io_ref ( struct io io)
static

Increment &io->ref_count

Parameters
iopoint to io data structure
Returns

Definition at line 70 of file io-mainloop.c.

References io::ref_count.

Referenced by io_callback(), and io_new().

ssize_t io_send ( struct io io,
const struct iovec *  iov,
int  iovcnt 
)

send data to the underlying socket (actual write)

Parameters
ioio structure which describe the underlying socket and its context
iovpointer to pdu, pdu length structure
iovcntnumber of pdu to send (iov is an array)
Returns
The return value is a count of bytes written, or -errno indicating an error.

Definition at line 395 of file io-mainloop.c.

References io::fd.

Referenced by can_write_data().

bool io_set_close_on_destroy ( struct io io,
bool  do_close 
)
Parameters
io
do_close
Returns

Definition at line 260 of file io-mainloop.c.

References io::close_on_destroy.

Referenced by bt_att_set_close_on_unref().

bool io_set_disconnect_handler ( struct io io,
io_callback_func_t  callback,
void *  user_data,
io_destroy_func_t  destroy 
)
Parameters
io
callback
user_data
destroy
Returns

Definition at line 356 of file io-mainloop.c.

References io::disconnect_callback, io::disconnect_data, io::disconnect_destroy, io::events, io::fd, and mainloop_modify_fd().

Referenced by bt_att_new().

bool io_set_read_handler ( struct io io,
io_callback_func_t  callback,
void *  user_data,
io_destroy_func_t  destroy 
)
Parameters
io
callback
user_data
destroy
Returns

Definition at line 278 of file io-mainloop.c.

References io::events, io::fd, mainloop_modify_fd(), io::read_callback, io::read_data, and io::read_destroy.

Referenced by bt_att_new().

bool io_set_write_handler ( struct io io,
io_callback_func_t  callback,
void *  user_data,
io_destroy_func_t  destroy 
)
Parameters
io
callback
user_data
destroy
Returns

Definition at line 317 of file io-mainloop.c.

References io::events, io::fd, mainloop_modify_fd(), io::write_callback, io::write_data, and io::write_destroy.

Referenced by wakeup_writer().

bool io_shutdown ( struct io io)
Parameters
io
Returns

Definition at line 417 of file io-mainloop.c.

References io::fd.

Referenced by can_read_data(), handle_conf(), handle_rsp(), and timeout_cb().

static void io_unref ( struct io io)
static

Decrement &io->ref_count and free io data structure when count reaches 0

Parameters
iopoint to io data structure
Returns

Definition at line 85 of file io-mainloop.c.

References io::ref_count.

Referenced by io_callback(), and io_destroy().