Maintained by: NLnet Labs
Data Structures | Enumerations | Functions
worker.h File Reference

This file describes the worker structure that holds a list of pending requests and handles them. More...

#include "libunbound/worker.h"
#include "util/netevent.h"
#include "util/locks.h"
#include "util/alloc.h"
#include "util/data/msgreply.h"
#include "util/data/msgparse.h"
#include "daemon/stats.h"
#include "util/module.h"
#include "dnstap/dnstap.h"

Data Structures

struct  worker
 Structure holding working information for unbound. More...


enum  worker_commands { worker_cmd_quit, worker_cmd_stats, worker_cmd_stats_noreset, worker_cmd_remote }
 worker commands More...


struct workerworker_create (struct daemon *daemon, int id, int *ports, int n)
 Create the worker structure. More...
int worker_init (struct worker *worker, struct config_file *cfg, struct listen_port *ports, int do_sigs)
 Initialize worker. More...
void worker_work (struct worker *worker)
 Make worker work.
void worker_delete (struct worker *worker)
 Delete worker.
void worker_send_cmd (struct worker *worker, enum worker_commands cmd)
 Send a command to a worker. More...
void worker_stats_clear (struct worker *worker)
 Init worker stats - includes server_stats_init, outside network and mesh. More...

Detailed Description

This file describes the worker structure that holds a list of pending requests and handles them.

Enumeration Type Documentation

◆ worker_commands

worker commands


make the worker quit


obtain statistics


obtain statistics without statsclear


execute remote control command

Function Documentation

◆ worker_create()

struct worker* worker_create ( struct daemon daemon,
int  id,
int *  ports,
int  n 

Create the worker structure.

Bare bones version, zeroed struct, with backpointers only. Use worker_init on it later.

daemonthe daemon that this worker thread is part of.
idthe thread number from 0.. numthreads-1.
portsthe ports it is allowed to use, array.
nthe number of ports.
: the new worker or NULL on alloc failure.

References daemon::cfg, worker::cmd, worker::daemon, config_file::dnstap, log_assert, log_err(), memdup(), worker::numports, worker::ports, daemon::rand, worker::rndstate, worker::thread_num, tube_create(), tube_delete(), and ub_initstate().

◆ worker_init()

int worker_init ( struct worker worker,
struct config_file cfg,
struct listen_port ports,
int  do_sigs 

Initialize worker.

Allocates event base, listens to ports

workerworker to initialize, created with worker_create.
cfgconfiguration settings.
portslist of shared query ports.
do_sigsif true, worker installs signal handlers.
: false on error.

References worker::base, and worker::need_to_exit.

Referenced by thread_start().

◆ worker_send_cmd()

void worker_send_cmd ( struct worker worker,
enum worker_commands  cmd 

Send a command to a worker.

Uses blocking writes.

workerworker to send command to.
cmdcommand to send.

References worker::cmd, log_err(), and tube_write_msg().

Referenced by daemon_stop_others(), distribute_cmd(), and server_stats_obtain().

◆ worker_stats_clear()

void worker_stats_clear ( struct worker worker)

Init worker stats - includes server_stats_init, outside network and mesh.

workerthe worker to init

References worker::back, module_env::cfg, worker::env, module_env::mesh, mesh_stats_clear(), outside_network::num_tcp_outgoing, server_stats_init(), worker::stats, and outside_network::unwanted_replies.

Referenced by do_flush_stats().