Commit 4a560920 authored by Daniel Salzman's avatar Daniel Salzman
Browse files

server: unify code + coding style

parent 110ff63a
Pipeline #33774 passed with stages
in 11 minutes and 32 seconds
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -62,7 +62,6 @@ static inline void unit_signalize_change(dt_unit_t *unit)
*/
static inline int dt_update_thread(dthread_t *thread, int state)
{
// Check
if (thread == 0) {
return KNOT_EINVAL;
}
......@@ -108,7 +107,6 @@ static inline int dt_update_thread(dthread_t *thread, int state)
*/
static void *thread_ep(void *data)
{
// Check data
dthread_t *thread = (dthread_t *)data;
if (thread == 0) {
return 0;
......@@ -233,7 +231,6 @@ static dthread_t *dt_create_thread(dt_unit_t *unit)
/*! \brief Delete single thread. */
static void dt_delete_thread(dthread_t **thread)
{
// Check
if (!thread || !*thread) {
return;
}
......@@ -252,13 +249,8 @@ static void dt_delete_thread(dthread_t **thread)
free(thr);
}
/*
* Public APIs.
*/
static dt_unit_t *dt_create_unit(int count)
{
// Check count
if (count <= 0) {
return 0;
}
......@@ -351,7 +343,6 @@ static dt_unit_t *dt_create_unit(int count)
dt_unit_t *dt_create(int count, runnable_t runnable, runnable_t destructor, void *data)
{
// Check count
if (count <= 0) {
return 0;
}
......@@ -389,7 +380,6 @@ void dt_delete(dt_unit_t **unit)
* Sorry.
*/
// Check
if (unit == 0) {
return;
}
......@@ -423,7 +413,6 @@ void dt_delete(dt_unit_t **unit)
static int dt_start_id(dthread_t *thread)
{
// Check input
if (thread == 0) {
return KNOT_EINVAL;
}
......@@ -462,7 +451,6 @@ static int dt_start_id(dthread_t *thread)
int dt_start(dt_unit_t *unit)
{
// Check input
if (unit == 0) {
return KNOT_EINVAL;
}
......@@ -490,7 +478,6 @@ int dt_start(dt_unit_t *unit)
int dt_signalize(dthread_t *thread, int signum)
{
// Check input
if (thread == 0) {
return KNOT_EINVAL;
}
......@@ -512,7 +499,6 @@ int dt_signalize(dthread_t *thread, int signum)
int dt_join(dt_unit_t *unit)
{
// Check input
if (unit == 0) {
return KNOT_EINVAL;
}
......@@ -565,7 +551,6 @@ int dt_join(dt_unit_t *unit)
int dt_stop(dt_unit_t *unit)
{
// Check unit
if (unit == 0) {
return KNOT_EINVAL;
}
......@@ -651,7 +636,6 @@ int dt_cancel(dthread_t *thread)
int dt_compact(dt_unit_t *unit)
{
// Check input
if (unit == 0) {
return KNOT_EINVAL;
}
......@@ -730,7 +714,6 @@ int dt_optimal_size(void)
int dt_is_cancelled(dthread_t *thread)
{
// Check input
if (thread == 0) {
return 0;
}
......@@ -756,14 +739,11 @@ unsigned dt_get_id(dthread_t *thread)
int dt_unit_lock(dt_unit_t *unit)
{
// Check input
if (unit == 0) {
return KNOT_EINVAL;
}
int ret = pthread_mutex_lock(&unit->_mx);
/* Map errors. */
if (ret < 0) {
return knot_map_errno();
}
......@@ -773,14 +753,11 @@ int dt_unit_lock(dt_unit_t *unit)
int dt_unit_unlock(dt_unit_t *unit)
{
// Check input
if (unit == 0) {
return KNOT_EINVAL;
}
int ret = pthread_mutex_unlock(&unit->_mx);
/* Map errors. */
if (ret < 0) {
return knot_map_errno();
}
......
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -14,10 +14,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*!
* \file dthreads.h
*
* \author Marek Vavrusa <marek.vavusa@nic.cz>
*
* \brief Threading API.
*
* Dynamic threads provide:
......@@ -31,9 +27,6 @@
*
* Incoherent function is when at least one thread executes
* a different runnable than the others.
*
* \addtogroup threading
* @{
*/
#pragma once
......@@ -299,5 +292,3 @@ int dt_unit_lock(dt_unit_t *unit);
* \retval KNOT_ERROR unspecified error.
*/
int dt_unit_unlock(dt_unit_t *unit);
/*! @} */
......@@ -28,6 +28,7 @@
#include "knot/conf/confio.h"
#include "knot/conf/migration.h"
#include "knot/conf/module.h"
#include "knot/dnssec/kasp/kasp_db.h"
#include "knot/server/server.h"
#include "knot/server/udp-handler.h"
#include "knot/server/tcp-handler.h"
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -13,17 +13,6 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*!
* \file
*
* \brief Core server functions.
*
* Contains the main high-level server structure (server_t) and interface
* to functions taking care of initialization of the server and clean-up.
*
* \addtogroup server
* @{
*/
#pragma once
......@@ -32,7 +21,6 @@
#include "knot/conf/conf.h"
#include "knot/common/evsched.h"
#include "knot/common/fdset.h"
#include "knot/dnssec/kasp/kasp_db.h"
#include "knot/server/dthreads.h"
#include "knot/common/ref.h"
#include "knot/worker/pool.h"
......@@ -191,5 +179,3 @@ void server_update_zones(conf_t *conf, server_t *server);
* \return new interface list
*/
ref_t *server_set_ifaces(server_t *server, fdset_t *fds, int index, int thread_id);
/*! @} */
......@@ -25,14 +25,13 @@
#include <stdio.h>
#include <stdlib.h>
#include <urcu.h>
#ifdef HAVE_SYS_UIO_H // struct iovec (OpenBSD)
#ifdef HAVE_SYS_UIO_H // struct iovec (OpenBSD)
#include <sys/uio.h>
#endif // HAVE_SYS_UIO_H
#include "dnssec/random.h"
#include "knot/server/server.h"
#include "knot/server/tcp-handler.h"
#include "knot/common/fdset.h"
#include "knot/common/log.h"
#include "knot/nameserver/process_query.h"
#include "knot/query/layer.h"
......@@ -55,11 +54,9 @@ typedef struct tcp_context {
unsigned thread_id; /*!< Thread identifier. */
} tcp_context_t;
/*
* Forward decls.
*/
#define TCP_THROTTLE_LO 0 /*!< Minimum recovery time on errors. */
#define TCP_THROTTLE_HI 2 /*!< Maximum recovery time on errors. */
#define TCP_SWEEP_INTERVAL 2 /*!< [secs] granularity of connection sweeping. */
#define TCP_THROTTLE_LO 0 /*!< Minimum recovery time on errors. */
#define TCP_THROTTLE_HI 2 /*!< Maximum recovery time on errors. */
/*! \brief Calculate TCP throttle time (random). */
static inline int tcp_throttle(void) {
......@@ -97,9 +94,6 @@ static bool tcp_send_state(int state)
return (state != KNOT_STATE_FAIL && state != KNOT_STATE_NOOP);
}
/*!
* \brief TCP event handler function.
*/
static int tcp_handle(tcp_context_t *tcp, int fd,
struct iovec *rx, struct iovec *tx)
{
......@@ -174,7 +168,7 @@ static int tcp_handle(tcp_context_t *tcp, int fd,
return ret;
}
int tcp_accept(int fd)
static int tcp_accept(int fd)
{
/* Accept incoming connection. */
int incoming = net_accept(fd, NULL);
......
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -14,36 +14,19 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*!
* \file tcp-handler.h
*
* \author Marek Vavrusa <marek.vavusa@nic.cz>
*
* \brief TCP sockets threading model.
*
* The master socket distributes incoming connections among
* the worker threads ("buckets"). Each threads processes it's own
* set of sockets, and eliminates mutual exclusion problem by doing so.
*
* \addtogroup server
* @{
*/
#pragma once
#include "knot/server/dthreads.h"
#define TCP_SWEEP_INTERVAL 2 /*!< [secs] granularity of connection sweeping. */
#define TCP_BACKLOG_SIZE 10 /*!< TCP listen backlog size. */
/*!
* \brief Accept a TCP connection.
* \param fd Associated socket.
*
* \retval Created connection fd if success.
* \retval <0 on error.
*/
int tcp_accept(int fd);
/*!
* \brief TCP handler thread runnable.
*
......@@ -57,5 +40,3 @@ int tcp_accept(int fd);
* \retval KNOT_EINVAL invalid parameters.
*/
int tcp_master(dthread_t *thread);
/*! @} */
......@@ -27,7 +27,7 @@
#include <assert.h>
#include <sys/param.h>
#include <urcu.h>
#ifdef HAVE_SYS_UIO_H /* 'struct iovec' for OpenBSD */
#ifdef HAVE_SYS_UIO_H // struct iovec (OpenBSD)
#include <sys/uio.h>
#endif /* HAVE_SYS_UIO_H */
......
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -14,18 +14,11 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*!
* \file udp-handler.h
*
* \author Marek Vavrusa <marek.vavusa@nic.cz>
*
* \brief UDP sockets threading model.
*
* The master socket locks one worker thread at a time
* and saves events in it's own backing store for asynchronous processing.
* The worker threads work asynchronously in thread pool.
*
* \addtogroup server
* @{
*/
#pragma once
......@@ -47,5 +40,3 @@
* \retval KNOT_EINVAL invalid parameters.
*/
int udp_master(dthread_t *thread);
/*! @} */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment