pianod2
multisource multiuser scriptable networked music player
Macros | Functions
fb_event.c File Reference

Football I/O event handlers. More...

#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdarg.h>
#include <ctype.h>
#include <errno.h>
#include <assert.h>
#include <sys/types.h>
#include <stdbool.h>
#include "fb_service.h"
Include dependency graph for fb_event.c:

Macros

#define _BSD_SOURCE   /* snprintf() */
 
#define _DEFAULT_SOURCE
 
#define _POSIX_C_SOURCE   200112L
 

Functions

static FB_MESSAGEfb_create_message (const char *format, va_list parameters)
 
static ssize_t fb_queue_single (FB_CONNECTION *connection, FB_MESSAGE *message)
 
static ssize_t fb_queue_broadcast (FB_SERVICE *service, FB_MESSAGE *message, bool(*callback)(FB_CONNECTION *))
 
ssize_t fb_queue_message (void *thing, FB_MESSAGE *message, bool broadcast)
 
ssize_t fb_fprint (void *thing, const char *bytes, ssize_t length)
 Adds an unformatted message to the output queue. More...
 
ssize_t fb_fprintf (void *thing, const char *format,...)
 Add messages to output queues in various forms and styles. More...
 
ssize_t fb_vfprintf (void *thing, const char *format, va_list parameters)
 
ssize_t fb_bfprintf (void *thing, const char *format,...)
 
ssize_t fb_bvfprintf (void *thing, const char *format, va_list parameters)
 
ssize_t fb_cbfprintf (void *thing, bool(*callback)(FB_CONNECTION *), const char *format,...)
 
ssize_t fb_cbvfprintf (void *thing, bool(*callback)(FB_CONNECTION *), const char *format, va_list parameters)
 
FB_EVENTfb_send_output (FB_EVENT *event, FB_CONNECTION *connection)
 
bool fb_set_input_buffer_size (FB_CONNECTION *connection, size_t size)
 
bool fb_recv_input (FB_CONNECTION *connection, ssize_t byte_count)
 
static char * fb_get_line_bytes (FB_CONNECTION *connection, size_t *length)
 
FB_EVENTfb_read_line_input (FB_EVENT *event, FB_CONNECTION *connection)
 
FB_EVENTfb_read_input (FB_EVENT *ev, FB_CONNECTION *connection)
 
FB_EVENTfb_new_connect (FB_EVENT *event, FB_SERVICE *service)
 

Detailed Description

Football I/O event handlers.

Macro Definition Documentation

◆ _BSD_SOURCE

#define _BSD_SOURCE   /* snprintf() */

◆ _DEFAULT_SOURCE

#define _DEFAULT_SOURCE

◆ _POSIX_C_SOURCE

#define _POSIX_C_SOURCE   200112L

Function Documentation

◆ fb_bfprintf()

ssize_t fb_bfprintf ( void *  thing,
const char *  format,
  ... 
)
See also
fb_fprintf
Here is the call graph for this function:

◆ fb_bvfprintf()

ssize_t fb_bvfprintf ( void *  thing,
const char *  format,
va_list  parameters 
)
See also
fb_fprintf
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fb_cbfprintf()

ssize_t fb_cbfprintf ( void *  thing,
bool(*)(FB_CONNECTION *)  callback,
const char *  format,
  ... 
)
See also
fb_fprintf
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fb_cbvfprintf()

ssize_t fb_cbvfprintf ( void *  thing,
bool(*)(FB_CONNECTION *)  callback,
const char *  format,
va_list  parameters 
)
See also
fb_fprintf
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fb_create_message()

static FB_MESSAGE* fb_create_message ( const char *  format,
va_list  parameters 
)
static

Create and populate a new message block.

Parameters
formata printf-style format string
parametersparameters to the format string
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fb_fprint()

ssize_t fb_fprint ( void *  thing,
const char *  bytes,
ssize_t  length 
)

Adds an unformatted message to the output queue.

Parameters
thingthe destined service, connection or event.
bytesthe bytes to transmit.
lengthnumber of bytes in the message.
Returns
-1 on error, number of bytes written on success or partial success.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fb_fprintf()

ssize_t fb_fprintf ( void *  thing,
const char *  format,
  ... 
)

Add messages to output queues in various forms and styles.

All forms take an opaque type and determine if it's a connection or service, so you can write code once and deal with both single and broadcast messages.

  • 'b' variants broadcast, given either a connection or service. Services always broadcast, regardless of service.
  • 'cb' variants broadcast only to those connections identified buy the supplied callback function returning true.
  • 'v' accepts a pointer to the format arguments.
    Parameters
    thingthe destined service, connection or event.
    formata printf format string, with values to follow.
    Returns
    -1 on error, number of bytes written on success or partial success.
Here is the call graph for this function:

◆ fb_get_line_bytes()

static char* fb_get_line_bytes ( FB_CONNECTION connection,
size_t *  length 
)
static

Read line-oriented input until encountering a newline. If there isn't a newline, the read input is kept in the connection's input buffer between invocations.

Parameters
connectionthe connection to read from.
lengththe number of bytes in the completed input
Returns
a pointer to the input, or NULL if it is not complete yet.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fb_new_connect()

FB_EVENT* fb_new_connect ( FB_EVENT event,
FB_SERVICE service 
)

Accept a new connection and return an event announcing it if applicable.

Parameters
eventa partially filled event applicable to the new connection.
servicethe service on which the connection is arriving.
Returns
FB_EVENT_CONNECTED for successful line-oriented connections, NULL otherwise.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fb_queue_broadcast()

static ssize_t fb_queue_broadcast ( FB_SERVICE service,
FB_MESSAGE message,
bool(*)(FB_CONNECTION *)  callback 
)
static

Put a message into all a service's queues.

Parameters
servicethe service to which the message will be sent.
messagethe message to send.
callbackIf NULL, broadcast to all connections. Otherwise, broadcast only if the specified callback function returns true.
Returns
length on success (queued to all connections successfully). On failure or partial failure, return -1.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fb_queue_message()

ssize_t fb_queue_message ( void *  thing,
FB_MESSAGE message,
bool  broadcast 
)

Add a message message to a service, connection, or event.

Parameters
thingThe service, connection or event to which message is sent.
messageThe message to send.
broadcastTrue if the message should be sent to all connections. Broadcast is inherently true if 'thing' is a service.
Returns
the length of the message, or -1 on error, as per stdio. In case of only partial success... Success.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fb_queue_single()

static ssize_t fb_queue_single ( FB_CONNECTION connection,
FB_MESSAGE message 
)
static

Put a message into a connection's output queue.

Parameters
connectionthe connection to which the message is to be sent.
messagea message to send.
Returns
length of message queued on success, or -1 on failure.

Add the message to the queue

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fb_read_input()

FB_EVENT* fb_read_input ( FB_EVENT ev,
FB_CONNECTION connection 
)

Read input based on protocol and state. If applicable, returns an event for the input.

  • FB_EVENT_INPUT is returned when there is input
  • FB_EVENT_CONNECT is returned on greeting or WebSocket establishment
    Parameters
    eva partially-filled event applicable to this input
    connectionthe connection from which input is read
    Returns
    an event (if applicable), or NULL.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fb_read_line_input()

FB_EVENT* fb_read_line_input ( FB_EVENT event,
FB_CONNECTION connection 
)

Read input from a connection, return it as an event. The event has the raw command in 'command'. The event has a broken up command in 'argv'. On failure, 'argv' may be null.

Parameters
eventa partially filled event applicable to the connection.
connectionthe connection from which input is read
Returns
An FB_EVENT_INPUT event, or input is incomplete.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fb_recv_input()

bool fb_recv_input ( FB_CONNECTION connection,
ssize_t  byte_count 
)

Read some bytes directly from a socket or via TLS if encrypted. Handle connection closing and errors.

Parameters
connectionthe connection to read input from.
byte_countthe number of bytes to read
Returns
true if the byte count is met, false otherwise.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fb_send_output()

FB_EVENT* fb_send_output ( FB_EVENT event,
FB_CONNECTION connection 
)

Write output to a connection from the queue. Events are generated for connection closure only; there are none for writing.

If the socket is in a closing state, when the buffer is empty, close the connection.

Parameters
eventA partially complete event record, or NULL. If NULL, events are delayed (along with moving state toward closure) until a later time, when an event can be returned for those state changes.
connectionThe connection whose queued data is to be sent.
Returns
FB_EVENT_CLOSE or NULL
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fb_set_input_buffer_size()

bool fb_set_input_buffer_size ( FB_CONNECTION connection,
size_t  size 
)

Expand the input buffer to a specified size.

Parameters
connectionThe connection whose buffer size is being set.
sizethe desired size.
Returns
true on success, false on failure.
Here is the caller graph for this function:

◆ fb_vfprintf()

ssize_t fb_vfprintf ( void *  thing,
const char *  format,
va_list  parameters 
)
See also
fb_fprintf
Here is the call graph for this function:
Here is the caller graph for this function: