|
pianod2
multisource multiuser scriptable networked music player
|
Football socket management and dispatching. More...
#include <config.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <errno.h>#include <time.h>#include <stdint.h>#include <sys/types.h>#include <sys/select.h>#include <assert.h>#include "fb_service.h"
Classes | |
| struct | socket_data_t |
Macros | |
| #define | _BSD_SOURCE /* strdup() */ |
| #define | _DARWIN_C_SOURCE /* strdup() on OS X */ |
| #define | _DEFAULT_SOURCE |
| #define | FD_COPY(from, to) memmove(to, from, sizeof(*(from))) |
| #define | fb_lock_socketmanager_mutex() true |
Typedefs | |
| typedef struct socket_data_t | FB_SOCKET_DATA |
| typedef enum select_action_t | ACTION |
Enumerations | |
| enum | select_action_t { ACTION_READING , ACTION_WRITING , ACTION_FAULTING , ACTION_BUFFERING , ACTION_COUNT , ACTION_SELECT_COUNT = 3 } |
Functions | |
| void | fb_schedule_reap (FB_SERVICE *service) |
| void | fb_queue_event (FB_EVENT *event) |
| void | fb_dispose_event (FB_EVENT *event) |
| void | fb_interrupt (void) |
| Return an FB_EVENT_INTERRUPTED on current or next poll. More... | |
| static bool | expand_socket_registry (int required_size) |
| bool | fb_register (int socket_fd, FB_SOCKETTYPE type, void *thing) |
| Add a socket to the registry. More... | |
| void | fb_unregister (int socket_fd) |
| Remove a socket from the registry. More... | |
| void | fb_set_socket_select_flags (int socket_fd, ACTION group, bool enable) |
| void | fb_set_buffering (int socket_fd, bool enable) |
| void | fb_set_writable (int socket_fd, bool enable) |
| void | fb_set_readable (int socket_fd, bool enable) |
| void | fb_accept_input (FB_CONNECTION *connection, bool input) |
| Public interface to enable/disable reading on a connection. More... | |
| FB_EVENT * | fb_process_event (int socket_fd, ACTION action) |
| static FB_EVENT * | fb_perform_reaping () |
| static void | subtract_from_timeval (struct timeval *minuend, const struct timeval *subtrahend) |
| static FB_EVENT * | fb_poll_for (struct timeval *timeout) |
| FB_EVENT * | fb_poll (void) |
| Quick poll with no waiting. More... | |
| FB_EVENT * | fb_poll_with_timeout (double timeout) |
| Poll with a duration. More... | |
| FB_EVENT * | fb_wait (void) |
| Poll indefinitely. More... | |
| FB_EVENT * | fb_poll_until (time_t untilwhen) |
| Poll with a timeout at a specific time. More... | |
Variables | |
| static FB_SERVICE * | reapq = NULL |
| static FB_SOCKET_DATA ** | sockets |
| Index by socket number to service/connection/etc. More... | |
| static int | maxsockets = 0 |
| static int | activesockets = 0 |
| static fd_set | select_state [ACTION_COUNT] |
| What we'll use on the next select() More... | |
| static fd_set | last_state [ACTION_SELECT_COUNT] |
| What came back on the last select() More... | |
| static FB_EVENT * | queued_event = NULL |
| Pending event (NULL if none, or single event. More... | |
| static bool | tls_currently_buffering |
| Set when TLS has stuff in its buffers. More... | |
| static volatile bool | interrupt_pending = false |
| Return EVENT_INTERRUPTED on EINTR. More... | |
Football socket management and dispatching.
| #define _BSD_SOURCE /* strdup() */ |
| #define _DARWIN_C_SOURCE /* strdup() on OS X */ |
| #define _DEFAULT_SOURCE |
| #define fb_lock_socketmanager_mutex | ( | ) | true |
| #define FD_COPY | ( | from, | |
| to | |||
| ) | memmove(to, from, sizeof(*(from))) |
| typedef enum select_action_t ACTION |
| typedef struct socket_data_t FB_SOCKET_DATA |
| enum select_action_t |
|
static |
Increase the registry to accommodate more sockets.
| required_size | The minimum size required. This function may choose to go larger. |

| void fb_accept_input | ( | FB_CONNECTION * | connection, |
| bool | input | ||
| ) |
Public interface to enable/disable reading on a connection.
| connection | - the connection to adjust. |
| input | true to enable reading, false to disable. |


| void fb_dispose_event | ( | FB_EVENT * | event | ) |
Destroy an event and free its resources. Events are all statically allocated, so we never free them in the current implementation. However, dispose frees the dynamically allocated elements and clears out the structure.
| event | the event to free |


| void fb_interrupt | ( | void | ) |
Return an FB_EVENT_INTERRUPTED on current or next poll.

|
static |
Remove items from the reap queue. Defer parent services until all children are dead.


| FB_EVENT* fb_poll | ( | void | ) |
Quick poll with no waiting.


|
static |
Poll the stuff in the registry. This is the worker function; the four exposed functions with various timeout mechanisms follow.
| timeout | Duration to poll, or NULL for indefinite wait. |


| FB_EVENT* fb_poll_until | ( | time_t | untilwhen | ) |
Poll with a timeout at a specific time.
| untilwhen | Time at which timeout should occur. |


| FB_EVENT* fb_poll_with_timeout | ( | double | timeout | ) |
Poll with a duration.
| timeout | in seconds. |


Called by the poll routine, this function takes a socket and an action and processes it, either inline or by calling another function to do the work.
| socket_fd | file descriptor of a socket that is ready/wants attention. |
| action | indicates if socket is ready for reading, writing, etc. |


| void fb_queue_event | ( | FB_EVENT * | event | ) |
Queue an event. Only used for fallback mode on HTTP port, when we need to deliver a connection arrival and then the command, so size is limited to 1.
| event | the event to queue |

| bool fb_register | ( | int | socket_fd, |
| FB_SOCKETTYPE | type, | ||
| void * | thing | ||
| ) |
Add a socket to the registry.
| socket_fd | The file descriptor of the socket being added. |
| type | Type of socket (service, connection, user...) |
| thing | Pointer of type indicated by 'type'. |


| void fb_schedule_reap | ( | FB_SERVICE * | service | ) |
Schedule a service for reaping when it has no connections left.

| void fb_set_buffering | ( | int | socket_fd, |
| bool | enable | ||
| ) |
Enable/disable writing on a socket. This is used to remember TLS data buffering.
| socket_fd | the file descriptor to apply flags to |
| enable | true if TLS is buffering, false if it is not. |


| void fb_set_readable | ( | int | socket_fd, |
| bool | enable | ||
| ) |
Enable/disable reading on a socket.
| socket_fd | the file descriptor to apply flags to |
| enable | true to enable reads from the socket, false to disable |


| void fb_set_socket_select_flags | ( | int | socket_fd, |
| ACTION | group, | ||
| bool | enable | ||
| ) |
Enable/disable the flags for selecting, or the buffering flags.
| socket_fd | the file descriptor to set flags for |
| group | which flags to adjust (read, write, ...) |
| enable | true to enable the flag, false to clear it |

| void fb_set_writable | ( | int | socket_fd, |
| bool | enable | ||
| ) |
Enable/disable writing on a socket. This is used within Football, enabled when fresh data is queued for a socket and disabled when the buffer is empty.
| socket_fd | the file descriptor to apply flags to |
| enable | true to enable write-polling on the socket |


| void fb_unregister | ( | int | socket_fd | ) |
Remove a socket from the registry.
Always succeeds, unless there's a bug.
| socket_fd | the file descriptor to unregister |

| FB_EVENT* fb_wait | ( | void | ) |
Poll indefinitely.


|
static |
Subtract time values.
| [in,out] | minuend | The time being subtracted from. |
| subtrahend | The value being subtracted. |

|
static |
|
static |
Return EVENT_INTERRUPTED on EINTR.
|
static |
What came back on the last select()
|
static |
|
static |
Pending event (NULL if none, or single event.
|
static |
|
static |
What we'll use on the next select()
|
static |
Index by socket number to service/connection/etc.
|
static |
Set when TLS has stuff in its buffers.