|
mod_tile 0.9.1
Renders map tiles with Mapnik and serves them using Apache HTTP Server
|
#include <arpa/inet.h>#include <errno.h>#include <glib.h>#include <limits.h>#include <netdb.h>#include <netinet/in.h>#include <poll.h>#include <pthread.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <strings.h>#include <sys/socket.h>#include <sys/stat.h>#include <sys/types.h>#include <sys/un.h>#include <unistd.h>#include <getopt.h>#include <signal.h>#include <time.h>#include "config.h"#include "g_logger.h"#include "gen_tile.h"#include "protocol.h"#include "protocol_helper.h"#include "render_config.h"#include "renderd.h"#include "renderd_config.h"#include "request_queue.h"Macros | |
| #define | PFD_LISTEN 0 |
| pollfd array index reserved for the incoming client listening socket. | |
| #define | PFD_EXIT_PIPE 1 |
| pollfd array index reserved for the self-pipe read end signaling graceful daemon shutdown. | |
| #define | PFD_SPECIAL_COUNT 2 |
| Number of fixed special descriptors preceding client connection slots in pfd[]. | |
Functions | |
| static const char * | cmdStr (enum protoCmd c) |
| Convert a wire protocol command enum value into a human-readable label for logging. | |
| void | send_response (struct item *item, enum protoCmd rsp, int render_time) |
| Complete a metatile render request, notify all waiting clients, and free its queue items. | |
| enum protoCmd | rx_request (struct protocol *req, int fd) |
| Normalize, validate, and enqueue an incoming wire protocol render or dirty request. | |
| void | request_exit (void) |
| Async-signal-safe shutdown trigger waking the main poll() event loop via exit_pipe_fd. | |
| void | process_loop (int listen_fd) |
| Main single-threaded poll() event loop accepting client connections and dispatching requests. | |
| void * | stats_writeout_thread (void *arg) |
| Background thread entry point atomically writing queue and render statistics every 10 seconds. | |
| int | client_socket_init (renderd_config *sConfig) |
| Open a client stream socket to a slave renderd instance over TCP or UNIX domain socket. | |
| static int | server_socket_init_tcp (renderd_config *sConfig) |
| Create and bind a dual-stack IPv6 (or fallback IPv4) TCP listening socket. | |
| int | server_socket_init (renderd_config *sConfig) |
| Create, bind, and start listening on the primary renderd TCP or UNIX domain server socket. | |
| void * | slave_thread (void *arg) |
| Worker thread entry point forwarding queued metatile jobs to a remote slave renderd. | |
| int | main (int argc, char **argv) |
| Entry point for the renderd Mapnik tile rendering daemon. | |
Variables | |
| static pthread_t * | render_threads |
| Array of local Mapnik worker thread handles (config->num_threads entries). | |
| static pthread_t * | slave_threads |
| Array of slave-dispatcher thread handles (num_slave_threads entries). | |
| static struct sigaction sigPipeAction | sigExitAction |
| Signal handler configuration ignoring SIGPIPE on broken client/slave sockets. | |
| static pthread_t | stats_thread |
| Background thread handle periodically flushing renderd statistics to disk. | |
| static int | exit_pipe_fd |
| Write end of the self-pipe written by request_exit() to wake process_loop(). | |
| struct request_queue * | render_request_queue |
| Global thread-safe render request queue shared by network I/O, local workers, and slave threads. | |
| #define PFD_EXIT_PIPE 1 |
pollfd array index reserved for the self-pipe read end signaling graceful daemon shutdown.
| #define PFD_LISTEN 0 |
pollfd array index reserved for the incoming client listening socket.
| #define PFD_SPECIAL_COUNT 2 |
Number of fixed special descriptors preceding client connection slots in pfd[].
| int client_socket_init | ( | renderd_config * | sConfig | ) |
Open a client stream socket to a slave renderd instance over TCP or UNIX domain socket.
| sConfig | Slave renderd_config specifying iphostname/ipport or socketname. |
|
static |
Convert a wire protocol command enum value into a human-readable label for logging.
| c | Wire protocol command opcode. |
| int main | ( | int | argc, |
| char ** | argv ) |
Entry point for the renderd Mapnik tile rendering daemon.
Parses command-line flags (-c/--config, -f/--foreground, -s/--slave, -h/--help, -V/--version), loads INI configuration, initializes the request queue, listening socket, signal handlers, Mapnik environment, optional daemonization/PID file, stats writer thread, local render threads, and slave threads, waits for map initialization, and runs process_loop().
| argc | Command-line argument count. |
| argv | Command-line argument vector. |
| void process_loop | ( | int | listen_fd | ) |
Main single-threaded poll() event loop accepting client connections and dispatching requests.
Monitors listen_fd, the shutdown self-pipe, and up to MAX_CONNECTIONS active client sockets; reads incoming protocol packets via recv_cmd(), enqueues valid requests through rx_request(), and cleans up disconnected client file descriptors.
| listen_fd | Bound and listening server socket file descriptor. |
| void request_exit | ( | void | ) |
Async-signal-safe shutdown trigger waking the main poll() event loop via exit_pipe_fd.
May be invoked safely from POSIX signal handlers (SIGINT, SIGTERM, SIGHUP) as well as worker threads encountering fatal startup errors.
Normalize, validate, and enqueue an incoming wire protocol render or dirty request.
Upgrades protocol v1/v2 packets to v3 defaults, validates the command opcode, allocates a struct item, aligns (x, y) coordinates down to the METATILE grid origin (mx, my), and inserts the item into render_request_queue.
| req | Parsed wire protocol request received from a client socket. |
| fd | Connected client socket descriptor (ignored/set to FD_INVALID for cmdDirty). |
Complete a metatile render request, notify all waiting clients, and free its queue items.
Removes item from render_request_queue, iterates through item and its coalesced duplicates chain, sends rsp (cmdDone or cmdNotDone) over each valid client socket awaiting a synchronous render, and frees every struct item node.
| item | Head of the completed metatile request (and duplicate subscriber) chain. |
| rsp | Completion status opcode (cmdDone or cmdNotDone). |
| render_time | Elapsed metatile render duration in milliseconds (or -1 if delegated/not rendered). |
| int server_socket_init | ( | renderd_config * | sConfig | ) |
Create, bind, and start listening on the primary renderd TCP or UNIX domain server socket.
When binding a UNIX domain socket, unlinks any stale socket file and temporarily sets umask(0) so Apache worker processes can connect to the daemon socket.
| sConfig | Active renderd_config specifying TCP port or UNIX socket path. |
|
static |
Create and bind a dual-stack IPv6 (or fallback IPv4) TCP listening socket.
Attempts to open an AF_INET6 socket with IPV6_V6ONLY disabled so both IPv6 and IPv4-mapped clients can connect; falls back to AF_INET if IPv6 is unavailable. Exits the daemon on fatal socket/bind errors.
| sConfig | Active renderd_config specifying iphostname and ipport. |
| void * slave_thread | ( | void * | arg | ) |
Worker thread entry point forwarding queued metatile jobs to a remote slave renderd.
Spawned once per configured slave worker slot (config_slaves[i].num_threads), each thread fetches one request at a time from render_request_queue, sends a v3 cmdRender packet to its slave daemon, blocks for the reply, and relays the result back via send_response().
| arg | Pointer to the target slave's renderd_config entry. |
| void * stats_writeout_thread | ( | void * | arg | ) |
Background thread entry point atomically writing queue and render statistics every 10 seconds.
Snapshots render_request_queue metrics, writes them to <stats_filename>.tmp, and atomically renames the file over config->stats_filename for external monitoring tools (e.g., Munin).
| arg | Unused thread argument (NULL). |
|
static |
Write end of the self-pipe written by request_exit() to wake process_loop().
| struct request_queue* render_request_queue |
Global thread-safe render request queue shared by network I/O, local workers, and slave threads.
|
static |
Array of local Mapnik worker thread handles (config->num_threads entries).
|
static |
Signal handler configuration ignoring SIGPIPE on broken client/slave sockets.
|
static |
Array of slave-dispatcher thread handles (num_slave_threads entries).
|
static |
Background thread handle periodically flushing renderd statistics to disk.