libre  0.6.0
Typedefs | Enumerations | Functions
re_main.h File Reference

Interface to main polling routine. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef void() fd_h(int flags, void *arg)
 File descriptor event handler. More...
 
typedef void() re_signal_h(int sig)
 Thread-safe signal handler. More...
 

Enumerations

enum  poll_method
 Polling methods.
 

Functions

int fd_listen (int fd, int flags, fd_h *fh, void *arg)
 Listen for events on a file descriptor. More...
 
void fd_close (int fd)
 Stop listening for events on a file descriptor. More...
 
int fd_setsize (int maxfds)
 Set the maximum number of file descriptors. More...
 
void fd_debug (void)
 Print all file descriptors in-use.
 
int libre_init (void)
 Initialise main library. More...
 
void libre_close (void)
 Close library and free up all resources.
 
int re_main (re_signal_h *signalh)
 Main polling loop for async I/O events. More...
 
void re_cancel (void)
 Cancel the main polling loop.
 
int re_debug (struct re_printf *pf, void *unused)
 Debug the main polling loop. More...
 
int re_thread_init (void)
 Add a worker thread for this thread. More...
 
void re_thread_close (void)
 Remove the worker thread for this thread.
 
void re_thread_enter (void)
 Enter an 're' thread. More...
 
void re_thread_leave (void)
 Leave an 're' thread. More...
 
void re_set_mutex (void *mutexp)
 Set an external mutex for this thread. More...
 
int poll_method_set (enum poll_method method)
 Set async I/O polling method. More...
 
enum poll_method poll_method_best (void)
 Choose the best async I/O polling method. More...
 
const char * poll_method_name (enum poll_method method)
 Get the name of the polling method. More...
 
int poll_method_type (enum poll_method *method, const struct pl *name)
 Get the polling method type from a string. More...
 

Detailed Description

Interface to main polling routine.

Copyright (C) 2010 Creytiv.com

Definition in file re_main.h.

Typedef Documentation

◆ fd_h

typedef void() fd_h(int flags, void *arg)

File descriptor event handler.

Parameters
flagsEvent flags
argHandler argument

Definition at line 25 of file re_main.h.

◆ re_signal_h

typedef void() re_signal_h(int sig)

Thread-safe signal handler.

Parameters
sigSignal number

Definition at line 32 of file re_main.h.

Function Documentation

◆ fd_close()

void fd_close ( int  fd)

Stop listening for events on a file descriptor.

Parameters
fdFile descriptor

Definition at line 643 of file main.c.

References fd_listen(), and NULL.

Referenced by udp_thread_detach().

◆ fd_listen()

int fd_listen ( int  fd,
int  flags,
fd_h fh,
void *  arg 
)

Listen for events on a file descriptor.

Parameters
fdFile descriptor
flagsWanted event flags
fhEvent handler
argHandler argument
Returns
0 if success, otherwise errorcode

Definition at line 564 of file main.c.

Referenced by fd_close(), tcp_set_send(), tcp_sock_listen(), and udp_thread_attach().

◆ fd_setsize()

int fd_setsize ( int  maxfds)

Set the maximum number of file descriptors.

Parameters
maxfdsMax FDs. 0 to free.
Returns
0 if success, otherwise errorcode

Definition at line 869 of file main.c.

Referenced by libre_close().

◆ libre_init()

int libre_init ( void  )

Initialise main library.

Returns
0 if success, errorcode if failure

Definition at line 20 of file init.c.

References rand_init().

◆ poll_method_best()

enum poll_method poll_method_best ( void  )

Choose the best async I/O polling method.

Returns
Polling method

Definition at line 24 of file method.c.

◆ poll_method_name()

const char* poll_method_name ( enum poll_method  method)

Get the name of the polling method.

Parameters
methodPolling method
Returns
Polling name string

Definition at line 64 of file method.c.

◆ poll_method_set()

int poll_method_set ( enum poll_method  method)

Set async I/O polling method.

This function can also be called while the program is running.

Parameters
methodNew polling method
Returns
0 if success, otherwise errorcode

Definition at line 1048 of file main.c.

◆ poll_method_type()

int poll_method_type ( enum poll_method method,
const struct pl name 
)

Get the polling method type from a string.

Parameters
methodReturned polling method
namePolling method name string
Returns
0 if success, otherwise errorcode

Definition at line 85 of file method.c.

References pl_strcasecmp().

◆ re_debug()

int re_debug ( struct re_printf pf,
void *  unused 
)

Debug the main polling loop.

Parameters
pfPrint handler where debug output is printed to
unusedUnused parameter
Returns
0 if success, otherwise errorcode

Definition at line 1023 of file main.c.

◆ re_main()

int re_main ( re_signal_h signalh)

Main polling loop for async I/O events.

This function will only return when re_cancel() is called or an error occured.

Parameters
signalhOptional Signal handler
Returns
0 if success, otherwise errorcode

Definition at line 937 of file main.c.

◆ re_set_mutex()

void re_set_mutex ( void *  mutexp)

Set an external mutex for this thread.

Parameters
mutexpPointer to external mutex, NULL to use internal

Definition at line 1191 of file main.c.

◆ re_thread_enter()

void re_thread_enter ( void  )

Enter an 're' thread.

Note
Must only be called from a non-re thread

Definition at line 1169 of file main.c.

References re_lock.

◆ re_thread_init()

int re_thread_init ( void  )

Add a worker thread for this thread.

Returns
0 if success, otherwise errorcode

Definition at line 1106 of file main.c.

References DEBUG_WARNING, EALREADY, and NULL.

◆ re_thread_leave()

void re_thread_leave ( void  )

Leave an 're' thread.

Note
Must only be called from a non-re thread

Definition at line 1180 of file main.c.

References re_unlock.