Dillo v3.1.1-119-g140d9ebd
Loading...
Searching...
No Matches
IO.c File Reference

Dillo's event driven IO engine. More...

#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include "../msg.h"
#include "../chain.h"
#include "../klist.h"
#include "IO.h"
#include "iowatch.hh"
#include "tls.h"
Include dependency graph for IO.c:

Go to the source code of this file.

Macros

#define IO_StopRd   1
 
#define IO_StopWr   2
 
#define IO_StopRdWr   (IO_StopRd | IO_StopWr)
 

Functions

void a_IO_ccc (int Op, int Branch, int Dir, ChainLink *Info, void *Data1, void *Data2)
 CCC function for the IO module.
 
static IOData_t * IO_new (int op)
 Return a new, initialized, 'io' struct.
 
static void IO_ins (IOData_t *io)
 Register an IO in ValidIOs.
 
static void IO_del (IOData_t *io)
 Remove an IO from ValidIOs.
 
static IOData_t * IO_get (int Key)
 Return a io by its Key (NULL if not found)
 
static void IO_free (IOData_t *io)
 Free an 'io' struct.
 
static void IO_close_fd (IOData_t *io, int CloseCode)
 Close an open FD, and remove io controls.
 
static bool_t IO_read (IOData_t *io)
 Read data from a file descriptor into a specific buffer.
 
static bool_t IO_write (IOData_t *io)
 Write data, from a specific buffer, into a file descriptor.
 
static int IO_callback (IOData_t *io)
 Handle background IO for a given FD (reads | writes).
 
static void IO_fd_read_cb (int fd, void *data)
 Handle the READ event of a FD.
 
static void IO_fd_write_cb (int fd, void *data)
 Handle the WRITE event of a FD.
 
static void IO_submit (IOData_t *r_io)
 Receive an IO request (IORead | IOWrite), Set a watch for it, and let it flow!
 

Variables

static Klist_tValidIOs = NULL
 

Detailed Description

Dillo's event driven IO engine.

Definition in file IO.c.

Macro Definition Documentation

◆ IO_StopRd

#define IO_StopRd   1

Definition at line 30 of file IO.c.

◆ IO_StopRdWr

#define IO_StopRdWr   (IO_StopRd | IO_StopWr)

Definition at line 32 of file IO.c.

◆ IO_StopWr

#define IO_StopWr   2

Definition at line 31 of file IO.c.

Function Documentation

◆ a_IO_ccc()

void a_IO_ccc ( int  Op,
int  Branch,
int  Dir,
ChainLink Info,
void *  Data1,
void *  Data2 
)

◆ IO_callback()

static int IO_callback ( IOData_t *  io)
static

Handle background IO for a given FD (reads | writes).

(This function gets called when there's activity in the FD)

Definition at line 265 of file IO.c.

References _MSG, FALSE, IO_read(), IO_write(), IORead, and IOWrite.

Referenced by IO_fd_read_cb(), and IO_fd_write_cb().

◆ IO_close_fd()

static void IO_close_fd ( IOData_t *  io,
int  CloseCode 
)
static

Close an open FD, and remove io controls.

(This function can be used for Close and Abort operations) BUG: there's a race condition for Abort. The file descriptor is closed twice, and it could be reused for something else in between. It's simple to fix, but it'd be better to design a canonical way to Abort the CCC.

Definition at line 125 of file IO.c.

References _MSG, a_IOwatch_remove_fd(), dClose(), DIO_READ, DIO_WRITE, IO_del(), IO_StopRd, IO_StopRdWr, and IO_StopWr.

Referenced by a_IO_ccc().

◆ IO_del()

static void IO_del ( IOData_t *  io)
static

Remove an IO from ValidIOs.

Definition at line 92 of file IO.c.

References _MSG, a_Klist_length(), a_Klist_remove(), and ValidIOs.

Referenced by IO_close_fd().

◆ IO_fd_read_cb()

static void IO_fd_read_cb ( int  fd,
void *  data 
)
static

Handle the READ event of a FD.

Definition at line 283 of file IO.c.

References a_IO_ccc(), a_IOwatch_remove_fd(), DIO_READ, FWD, IO_callback(), IO_get(), MSG_ERR, OpAbort, and VOIDP2INT.

Referenced by IO_submit().

◆ IO_fd_write_cb()

static void IO_fd_write_cb ( int  fd,
void *  data 
)
static

Handle the WRITE event of a FD.

Definition at line 306 of file IO.c.

References a_IO_ccc(), a_IOwatch_remove_fd(), DIO_WRITE, FWD, IO_callback(), IO_get(), MSG_ERR, OpAbort, and VOIDP2INT.

Referenced by IO_submit().

◆ IO_free()

static void IO_free ( IOData_t *  io)
static

Free an 'io' struct.

Definition at line 112 of file IO.c.

References dFree(), and dStr_free().

Referenced by a_IO_ccc().

◆ IO_get()

static IOData_t * IO_get ( int  Key)
static

Return a io by its Key (NULL if not found)

Definition at line 104 of file IO.c.

References a_Klist_get_data(), and ValidIOs.

Referenced by IO_fd_read_cb(), IO_fd_write_cb(), and IO_read().

◆ IO_ins()

static void IO_ins ( IOData_t *  io)
static

Register an IO in ValidIOs.

Definition at line 80 of file IO.c.

References _MSG, a_Klist_insert(), a_Klist_length(), and ValidIOs.

Referenced by IO_submit().

◆ IO_new()

static IOData_t * IO_new ( int  op)
static

Return a new, initialized, 'io' struct.

Definition at line 64 of file IO.c.

References dNew0, dStr_sized_new(), and IOBufLen.

Referenced by a_IO_ccc().

◆ IO_read()

static bool_t IO_read ( IOData_t *  io)
static

Read data from a file descriptor into a specific buffer.

Definition at line 157 of file IO.c.

References _MSG, a_IO_ccc(), a_Tls_connection(), a_Tls_read(), dStr_append_l(), dStr_truncate(), FALSE, FWD, IO_get(), IOBufLen, MSG, OpEnd, OpSend, and TRUE.

Referenced by IO_callback().

◆ IO_submit()

static void IO_submit ( IOData_t *  r_io)
static

Receive an IO request (IORead | IOWrite), Set a watch for it, and let it flow!

Definition at line 328 of file IO.c.

References _MSG, a_IOwatch_add_fd(), DIO_READ, DIO_WRITE, INT2VOIDP, IO_fd_read_cb(), IO_fd_write_cb(), IO_ins(), IORead, IOWrite, and MSG_ERR.

Referenced by a_IO_ccc().

◆ IO_write()

static bool_t IO_write ( IOData_t *  io)
static

Write data, from a specific buffer, into a file descriptor.

Definition at line 219 of file IO.c.

References _MSG, a_Tls_connection(), a_Tls_write(), dStr_erase(), dStr_truncate(), FALSE, MSG, and TRUE.

Referenced by IO_callback().

Variable Documentation

◆ ValidIOs

Klist_t* ValidIOs = NULL
static

Definition at line 49 of file IO.c.

Referenced by IO_del(), IO_get(), and IO_ins().