libu8
Data Structures | Typedefs | Functions
include/libu8/u8srvfns.h File Reference

These functions provide a scaffolding for internet servers of various sorts, implementing a simple thread pool and listener model. More...

Data Structures

struct  U8_CLIENT
 struct U8_CLIENT This structure represents a particular live client of a server. More...
struct  U8_SERVER_INFO
 struct U8_SERVER_INFO describes information about a particular server socket used to listen for new connections. More...
struct  U8_SERVER
 struct U8_SERVER This structure represents a server's state and connections. More...

Typedefs

typedef struct U8_CLIENT U8_CLIENT
 struct U8_CLIENT This structure represents a particular live client of a server.
typedef struct U8_SERVER_INFO U8_SERVER_INFO
 struct U8_SERVER_INFO describes information about a particular server socket used to listen for new connections.
typedef struct U8_SERVER U8_SERVER
 struct U8_SERVER This structure represents a server's state and connections.

Functions

U8_EXPORT void u8_client_close (u8_client cl)
 Forces a client to be closed.
U8_EXPORT int u8_add_server (struct U8_SERVER *server, char *hostname, int port)
 Configures a server to listen on a particular address (port/host or file)
U8_EXPORT void u8_server_loop (struct U8_SERVER *server)
 Starts a loop listening for requests to a server.
U8_EXPORT int u8_server_shutdown (struct U8_SERVER *server)
 Shuts down a server, stopping listening and closing all connections when completed.
U8_EXPORT u8_string u8_server_status (struct U8_SERVER *server, u8_byte *buf, int buflen)
 Returns a user readable string describing the server's status, including active and pending tasks, total transactions, etc.
U8_EXPORT u8_string u8_server_status_raw (struct U8_SERVER *server, u8_byte *buf, int buflen)
 Returns a machine readable (tab-separated) string describing the server's status, including active and pending tasks, total transactions, etc.

Detailed Description

These functions provide a scaffolding for internet servers of various sorts, implementing a simple thread pool and listener model.


Typedef Documentation

typedef struct U8_CLIENT U8_CLIENT

struct U8_CLIENT This structure represents a particular live client of a server.

The socket field is the socket going to the client, the flags field contains flags describing the configuration and state of the client, the idstring field is a string identify the client for logging and debugging, and the server field is the server (a U8_SERVER struct) to which the client is connected.


Function Documentation

U8_EXPORT int u8_add_server ( struct U8_SERVER server,
char *  hostname,
int  port 
)

Configures a server to listen on a particular address (port/host or file)

Parameters:
servera pointer to a U8_SERVER struct
hostname(a utf-8 string) the hostname to listen for
port(an int) the port to listen on
Returns:
void
U8_EXPORT void u8_client_close ( u8_client  cl)

Forces a client to be closed.

Parameters:
cla pointer to a U8_CLIENT struct
Returns:
void
U8_EXPORT void u8_server_loop ( struct U8_SERVER server)

Starts a loop listening for requests to a server.

Parameters:
servera pointer to a U8_SERVER struct
Returns:
void
U8_EXPORT int u8_server_shutdown ( struct U8_SERVER server)

Shuts down a server, stopping listening and closing all connections when completed.

Parameters:
servera pointer to a U8_SERVER struct
Returns:
1 if the server was newly and successfully closed
U8_EXPORT u8_string u8_server_status ( struct U8_SERVER server,
u8_byte *  buf,
int  buflen 
)

Returns a user readable string describing the server's status, including active and pending tasks, total transactions, etc.

Parameters:
servera pointer to a U8_SERVER struct
bufNULL or a pointer to a buffer for the report
buflenthe size of buf if non NULL
Returns:
the string of status information; if BUF was NULL, this was mallocd; otherwise, it is BUF with the output truncated to buflen
U8_EXPORT u8_string u8_server_status_raw ( struct U8_SERVER server,
u8_byte *  buf,
int  buflen 
)

Returns a machine readable (tab-separated) string describing the server's status, including active and pending tasks, total transactions, etc.

Parameters:
servera pointer to a U8_SERVER struct
bufNULL or a pointer to a buffer for the report
buflenthe size of buf if non NULL
Returns:
the string of status information; if BUF was NULL, this was mallocd; otherwise, it is BUF with the output truncated to buflen