fixup! WIP: Add isc_work_queue() to replace isc_nm_offload_work() - but don't use it yet
This commit is contained in:
@@ -100,7 +100,9 @@ libisc_la_HEADERS = \
|
||||
include/isc/types.h \
|
||||
include/isc/url.h \
|
||||
include/isc/utf8.h \
|
||||
include/isc/util.h
|
||||
include/isc/util.h \
|
||||
include/isc/uv.h \
|
||||
include/isc/work.h
|
||||
|
||||
libisc_la_SOURCES = \
|
||||
$(libisc_la_HEADERS) \
|
||||
@@ -111,9 +113,6 @@ libisc_la_SOURCES = \
|
||||
netmgr/timer.c \
|
||||
netmgr/tlsdns.c \
|
||||
netmgr/udp.c \
|
||||
netmgr/uv-compat.c \
|
||||
netmgr/uv-compat.h \
|
||||
netmgr/uverr2result.c \
|
||||
aes.c \
|
||||
assertions.c \
|
||||
astack.c \
|
||||
@@ -205,7 +204,9 @@ libisc_la_SOURCES = \
|
||||
trampoline.c \
|
||||
trampoline_p.h \
|
||||
url.c \
|
||||
utf8.c
|
||||
utf8.c \
|
||||
uv.c \
|
||||
work.c
|
||||
|
||||
libisc_la_CPPFLAGS = \
|
||||
$(AM_CPPFLAGS) \
|
||||
|
||||
@@ -29,6 +29,11 @@ typedef struct isc_signal isc_signal_t;
|
||||
|
||||
typedef void (*isc_signal_cb)(void *, int);
|
||||
|
||||
typedef struct isc_work isc_work_t;
|
||||
|
||||
typedef void (*isc_work_cb)(void *arg);
|
||||
typedef void (*isc_after_work_cb)(void *arg, isc_result_t result);
|
||||
|
||||
#define ISC_LOOPMGR_TID_UNKNOWN UINT32_MAX
|
||||
|
||||
ISC_LANG_BEGINDECLS
|
||||
@@ -118,9 +123,9 @@ isc_loopmgr_resume(isc_loopmgr_t *loopmgr);
|
||||
*\li We are in a running loop.
|
||||
*/
|
||||
|
||||
void
|
||||
isc_job_t *
|
||||
isc_loop_setup(isc_loop_t *loop, isc_job_cb cb, void *cbarg);
|
||||
void
|
||||
isc_job_t *
|
||||
isc_loop_teardown(isc_loop_t *loop, isc_job_cb cb, void *cbarg);
|
||||
/*%<
|
||||
* Schedule actions to be run when starting, and when shutting down,
|
||||
@@ -132,6 +137,11 @@ isc_loop_teardown(isc_loop_t *loop, isc_job_cb cb, void *cbarg);
|
||||
* yet been started.
|
||||
*/
|
||||
|
||||
void
|
||||
isc_loop_nosetup(isc_loop_t *loop, isc_job_t *job);
|
||||
void
|
||||
isc_loop_noteardown(isc_loop_t *loop, isc_job_t *job);
|
||||
|
||||
void
|
||||
isc_loopmgr_setup(isc_loopmgr_t *loopmgr, isc_job_cb cb, void *cbarg);
|
||||
void
|
||||
|
||||
@@ -30,9 +30,9 @@
|
||||
#include <isc/strerr.h>
|
||||
#include <isc/thread.h>
|
||||
#include <isc/util.h>
|
||||
#include <isc/uv.h>
|
||||
|
||||
#include "loop_p.h"
|
||||
#include "netmgr/uv-compat.h"
|
||||
|
||||
/**
|
||||
* Private
|
||||
@@ -240,6 +240,30 @@ enum {
|
||||
};
|
||||
|
||||
static void
|
||||
isc__loop_deschedule(isc_loop_t *loop, int when, isc_job_t *job) {
|
||||
switch (when) {
|
||||
case isc_loop_ctor:
|
||||
ISC_LIST_DEQUEUE(loop->setup_jobs, job, link);
|
||||
break;
|
||||
case isc_loop_dtor:
|
||||
ISC_LIST_DEQUEUE(loop->teardown_jobs, job, link);
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
isc_loop_nosetup(isc_loop_t *loop, isc_job_t *job) {
|
||||
isc__loop_deschedule(loop, isc_loop_ctor, job);
|
||||
}
|
||||
|
||||
void
|
||||
isc_loop_noteardown(isc_loop_t *loop, isc_job_t *job) {
|
||||
isc__loop_deschedule(loop, isc_loop_dtor, job);
|
||||
}
|
||||
|
||||
static isc_job_t *
|
||||
isc__loop_schedule(isc_loop_t *loop, int when, isc_job_cb cb, void *cbarg) {
|
||||
isc_job_t *job = NULL;
|
||||
isc_loopmgr_t *loopmgr;
|
||||
@@ -283,6 +307,7 @@ isc__loop_schedule(isc_loop_t *loop, int when, isc_job_cb cb, void *cbarg) {
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
return (job);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -337,14 +362,14 @@ isc_loopmgr_new(isc_mem_t *mctx, uint32_t nloops) {
|
||||
return (loopmgr);
|
||||
}
|
||||
|
||||
void
|
||||
isc_job_t *
|
||||
isc_loop_setup(isc_loop_t *loop, isc_job_cb cb, void *cbarg) {
|
||||
isc__loop_schedule(loop, isc_loop_ctor, cb, cbarg);
|
||||
return (isc__loop_schedule(loop, isc_loop_ctor, cb, cbarg));
|
||||
}
|
||||
|
||||
void
|
||||
isc_job_t *
|
||||
isc_loop_teardown(isc_loop_t *loop, isc_job_cb cb, void *cbarg) {
|
||||
isc__loop_schedule(loop, isc_loop_dtor, cb, cbarg);
|
||||
return (isc__loop_schedule(loop, isc_loop_dtor, cb, cbarg));
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
|
||||
#include <isc/barrier.h>
|
||||
#include <isc/lang.h>
|
||||
#include <isc/loop.h>
|
||||
#include <isc/magic.h>
|
||||
#include <isc/mem.h>
|
||||
#include <isc/refcount.h>
|
||||
#include <isc/result.h>
|
||||
@@ -45,6 +47,15 @@ struct isc_job {
|
||||
LINK(isc_job_t) link;
|
||||
};
|
||||
|
||||
struct isc_work {
|
||||
uv_work_t work;
|
||||
isc_loop_t *loop;
|
||||
isc_work_cb work_cb;
|
||||
isc_after_work_cb after_work_cb;
|
||||
isc_job_t *cancel_job;
|
||||
void *cbarg;
|
||||
};
|
||||
|
||||
struct isc_loop {
|
||||
int magic;
|
||||
isc_refcount_t references;
|
||||
@@ -99,10 +110,3 @@ struct isc_loopmgr {
|
||||
/* per-thread objects */
|
||||
isc_loop_t *loops;
|
||||
};
|
||||
|
||||
/* FIXME: Deduplicate with netmgr-int.h */
|
||||
#define UV_RUNTIME_CHECK(func, ret) \
|
||||
if (ret != 0) { \
|
||||
isc_error_fatal(__FILE__, __LINE__, "%s failed: %s\n", #func, \
|
||||
uv_strerror(ret)); \
|
||||
}
|
||||
|
||||
@@ -37,8 +37,7 @@
|
||||
#include <isc/thread.h>
|
||||
#include <isc/tls.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include "uv-compat.h"
|
||||
#include <isc/uv.h>
|
||||
|
||||
#define ISC_NETMGR_TID_UNKNOWN -1
|
||||
|
||||
|
||||
@@ -39,12 +39,12 @@
|
||||
#include <isc/thread.h>
|
||||
#include <isc/tls.h>
|
||||
#include <isc/util.h>
|
||||
#include <isc/uv.h>
|
||||
|
||||
#include "netmgr-int.h"
|
||||
#include "netmgr_p.h"
|
||||
#include "openssl_shim.h"
|
||||
#include "trampoline_p.h"
|
||||
#include "uv-compat.h"
|
||||
|
||||
/*%
|
||||
* How many isc_nmhandles and isc_nm_uvreqs will we be
|
||||
|
||||
@@ -33,9 +33,9 @@
|
||||
#include <isc/stdtime.h>
|
||||
#include <isc/thread.h>
|
||||
#include <isc/util.h>
|
||||
#include <isc/uv.h>
|
||||
|
||||
#include "netmgr-int.h"
|
||||
#include "uv-compat.h"
|
||||
|
||||
static atomic_uint_fast32_t last_tcpquota_log = 0;
|
||||
|
||||
|
||||
@@ -33,9 +33,9 @@
|
||||
#include <isc/stdtime.h>
|
||||
#include <isc/thread.h>
|
||||
#include <isc/util.h>
|
||||
#include <isc/uv.h>
|
||||
|
||||
#include "netmgr-int.h"
|
||||
#include "uv-compat.h"
|
||||
|
||||
static atomic_uint_fast32_t last_tcpdnsquota_log = 0;
|
||||
|
||||
|
||||
@@ -33,10 +33,10 @@
|
||||
#include <isc/stdtime.h>
|
||||
#include <isc/thread.h>
|
||||
#include <isc/util.h>
|
||||
#include <isc/uv.h>
|
||||
|
||||
#include "netmgr-int.h"
|
||||
#include "openssl_shim.h"
|
||||
#include "uv-compat.h"
|
||||
|
||||
static atomic_uint_fast32_t last_tlsdnsquota_log = 0;
|
||||
|
||||
|
||||
@@ -36,10 +36,10 @@
|
||||
#include <isc/stdtime.h>
|
||||
#include <isc/thread.h>
|
||||
#include <isc/util.h>
|
||||
#include <isc/uv.h>
|
||||
|
||||
#include "../openssl_shim.h"
|
||||
#include "netmgr-int.h"
|
||||
#include "uv-compat.h"
|
||||
|
||||
#define TLS_BUF_SIZE (UINT16_MAX)
|
||||
|
||||
|
||||
@@ -29,9 +29,9 @@
|
||||
#include <isc/sockaddr.h>
|
||||
#include <isc/thread.h>
|
||||
#include <isc/util.h>
|
||||
#include <isc/uv.h>
|
||||
|
||||
#include "netmgr-int.h"
|
||||
#include "uv-compat.h"
|
||||
|
||||
#ifdef HAVE_NET_ROUTE_H
|
||||
#include <net/route.h>
|
||||
|
||||
@@ -14,96 +14,4 @@
|
||||
#pragma once
|
||||
#include <uv.h>
|
||||
|
||||
/*
|
||||
* These functions were introduced in newer libuv, but we still
|
||||
* want BIND9 compile on older ones so we emulate them.
|
||||
* They're inline to avoid conflicts when running with a newer
|
||||
* library version.
|
||||
*/
|
||||
|
||||
#define UV_VERSION(major, minor, patch) ((major << 16) | (minor << 8) | (patch))
|
||||
|
||||
#if !defined(UV__ERR)
|
||||
#define UV__ERR(x) (-(x))
|
||||
#endif
|
||||
|
||||
#if UV_VERSION_HEX < UV_VERSION(1, 19, 0)
|
||||
static inline void *
|
||||
uv_handle_get_data(const uv_handle_t *handle) {
|
||||
return (handle->data);
|
||||
}
|
||||
|
||||
static inline void
|
||||
uv_handle_set_data(uv_handle_t *handle, void *data) {
|
||||
handle->data = data;
|
||||
}
|
||||
|
||||
static inline void *
|
||||
uv_req_get_data(const uv_req_t *req) {
|
||||
return (req->data);
|
||||
}
|
||||
|
||||
static inline void
|
||||
uv_req_set_data(uv_req_t *req, void *data) {
|
||||
req->data = data;
|
||||
}
|
||||
#endif /* UV_VERSION_HEX < UV_VERSION(1, 19, 0) */
|
||||
|
||||
#if UV_VERSION_HEX < UV_VERSION(1, 32, 0)
|
||||
int
|
||||
uv_tcp_close_reset(uv_tcp_t *handle, uv_close_cb close_cb);
|
||||
#endif
|
||||
|
||||
#if UV_VERSION_HEX < UV_VERSION(1, 34, 0)
|
||||
#define uv_sleep(msec) usleep(msec * 1000)
|
||||
#endif /* UV_VERSION_HEX < UV_VERSION(1, 34, 0) */
|
||||
|
||||
#if UV_VERSION_HEX < UV_VERSION(1, 27, 0)
|
||||
int
|
||||
isc_uv_udp_connect(uv_udp_t *handle, const struct sockaddr *addr);
|
||||
/*%<
|
||||
* Associate the UDP handle to a remote address and port, so every message sent
|
||||
* by this handle is automatically sent to that destination.
|
||||
*
|
||||
* NOTE: This is just a limited shim for uv_udp_connect() as it requires the
|
||||
* handle to be bound.
|
||||
*/
|
||||
#else /* UV_VERSION_HEX < UV_VERSION(1, 27, 0) */
|
||||
#define isc_uv_udp_connect uv_udp_connect
|
||||
#endif /* UV_VERSION_HEX < UV_VERSION(1, 27, 0) */
|
||||
|
||||
#if UV_VERSION_HEX < UV_VERSION(1, 12, 0)
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static inline int
|
||||
uv_os_getenv(const char *name, char *buffer, size_t *size) {
|
||||
size_t len;
|
||||
char *buf = getenv(name);
|
||||
|
||||
if (buf == NULL) {
|
||||
return (UV_ENOENT);
|
||||
}
|
||||
|
||||
len = strlen(buf) + 1;
|
||||
if (len > *size) {
|
||||
*size = len;
|
||||
return (UV_ENOBUFS);
|
||||
}
|
||||
|
||||
*size = len;
|
||||
memmove(buffer, buf, len);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
#define uv_os_setenv(name, value) setenv(name, value, 0)
|
||||
#endif /* UV_VERSION_HEX < UV_VERSION(1, 12, 0) */
|
||||
|
||||
int
|
||||
isc_uv_udp_freebind(uv_udp_t *handle, const struct sockaddr *addr,
|
||||
unsigned int flags);
|
||||
|
||||
int
|
||||
isc_uv_tcp_freebind(uv_tcp_t *handle, const struct sockaddr *addr,
|
||||
unsigned int flags);
|
||||
#include <isc/uv.h>
|
||||
|
||||
@@ -20,85 +20,3 @@
|
||||
#include <isc/util.h>
|
||||
|
||||
#include "netmgr-int.h"
|
||||
|
||||
/*%
|
||||
* Convert a libuv error value into an isc_result_t. The
|
||||
* list of supported error values is not complete; new users
|
||||
* of this function should add any expected errors that are
|
||||
* not already there.
|
||||
*/
|
||||
isc_result_t
|
||||
isc___nm_uverr2result(int uverr, bool dolog, const char *file,
|
||||
unsigned int line, const char *func) {
|
||||
switch (uverr) {
|
||||
case 0:
|
||||
return (ISC_R_SUCCESS);
|
||||
case UV_ENOTDIR:
|
||||
case UV_ELOOP:
|
||||
case UV_EINVAL: /* XXX sometimes this is not for files */
|
||||
case UV_ENAMETOOLONG:
|
||||
case UV_EBADF:
|
||||
return (ISC_R_INVALIDFILE);
|
||||
case UV_ENOENT:
|
||||
return (ISC_R_FILENOTFOUND);
|
||||
case UV_EAGAIN:
|
||||
return (ISC_R_NOCONN);
|
||||
case UV_EACCES:
|
||||
case UV_EPERM:
|
||||
return (ISC_R_NOPERM);
|
||||
case UV_EEXIST:
|
||||
return (ISC_R_FILEEXISTS);
|
||||
case UV_EIO:
|
||||
return (ISC_R_IOERROR);
|
||||
case UV_ENOMEM:
|
||||
return (ISC_R_NOMEMORY);
|
||||
case UV_ENFILE:
|
||||
case UV_EMFILE:
|
||||
return (ISC_R_TOOMANYOPENFILES);
|
||||
case UV_ENOSPC:
|
||||
return (ISC_R_DISCFULL);
|
||||
case UV_EPIPE:
|
||||
case UV_ECONNRESET:
|
||||
case UV_ECONNABORTED:
|
||||
return (ISC_R_CONNECTIONRESET);
|
||||
case UV_ENOTCONN:
|
||||
return (ISC_R_NOTCONNECTED);
|
||||
case UV_ETIMEDOUT:
|
||||
return (ISC_R_TIMEDOUT);
|
||||
case UV_ENOBUFS:
|
||||
return (ISC_R_NORESOURCES);
|
||||
case UV_EAFNOSUPPORT:
|
||||
return (ISC_R_FAMILYNOSUPPORT);
|
||||
case UV_ENETDOWN:
|
||||
return (ISC_R_NETDOWN);
|
||||
case UV_EHOSTDOWN:
|
||||
return (ISC_R_HOSTDOWN);
|
||||
case UV_ENETUNREACH:
|
||||
return (ISC_R_NETUNREACH);
|
||||
case UV_EHOSTUNREACH:
|
||||
return (ISC_R_HOSTUNREACH);
|
||||
case UV_EADDRINUSE:
|
||||
return (ISC_R_ADDRINUSE);
|
||||
case UV_EADDRNOTAVAIL:
|
||||
return (ISC_R_ADDRNOTAVAIL);
|
||||
case UV_ECONNREFUSED:
|
||||
return (ISC_R_CONNREFUSED);
|
||||
case UV_ECANCELED:
|
||||
return (ISC_R_CANCELED);
|
||||
case UV_EOF:
|
||||
return (ISC_R_EOF);
|
||||
case UV_EMSGSIZE:
|
||||
return (ISC_R_MAXSIZE);
|
||||
case UV_ENOTSUP:
|
||||
return (ISC_R_FAMILYNOSUPPORT);
|
||||
default:
|
||||
if (dolog) {
|
||||
UNEXPECTED_ERROR(
|
||||
file, line,
|
||||
"unable to convert libuv "
|
||||
"error code in %s to isc_result: %d: %s",
|
||||
func, uverr, uv_strerror(uverr));
|
||||
}
|
||||
return (ISC_R_UNEXPECTED);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
|
||||
#include <isc/loop.h>
|
||||
#include <isc/signal.h>
|
||||
#include <isc/uv.h>
|
||||
|
||||
#include "loop_p.h"
|
||||
#include "netmgr/uv-compat.h"
|
||||
|
||||
isc_signal_t *
|
||||
isc_signal_new(isc_loopmgr_t *loopmgr, isc_signal_cb cb, void *cbarg,
|
||||
|
||||
@@ -37,14 +37,13 @@
|
||||
#include <isc/refcount.h>
|
||||
#include <isc/sockaddr.h>
|
||||
#include <isc/thread.h>
|
||||
#include <isc/uv.h>
|
||||
|
||||
#include "uv_wrap.h"
|
||||
#define KEEP_BEFORE
|
||||
|
||||
#include "../netmgr/http.c"
|
||||
#include "../netmgr/netmgr-int.h"
|
||||
#include "../netmgr/uv-compat.c"
|
||||
#include "../netmgr/uv-compat.h"
|
||||
#include "../netmgr_p.h"
|
||||
#include "isctest.h"
|
||||
|
||||
|
||||
@@ -30,14 +30,13 @@
|
||||
#include <isc/sockaddr.h>
|
||||
#include <isc/thread.h>
|
||||
#include <isc/util.h>
|
||||
#include <isc/uv.h>
|
||||
|
||||
#include "uv_wrap.h"
|
||||
#define KEEP_BEFORE
|
||||
|
||||
#include "../netmgr/netmgr-int.h"
|
||||
#include "../netmgr/udp.c"
|
||||
#include "../netmgr/uv-compat.c"
|
||||
#include "../netmgr/uv-compat.h"
|
||||
#include "../netmgr_p.h"
|
||||
#include "isctest.h"
|
||||
|
||||
|
||||
@@ -26,12 +26,11 @@
|
||||
#include <uv.h>
|
||||
|
||||
#include <isc/atomic.h>
|
||||
#include <isc/uv.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include "../netmgr/uv-compat.h"
|
||||
|
||||
/* uv_udp_t */
|
||||
|
||||
int
|
||||
|
||||
@@ -38,7 +38,16 @@ isc__after_work_cb(uv_work_t *req, int status) {
|
||||
|
||||
work->after_work_cb(work->cbarg, result);
|
||||
|
||||
isc_mem_put(work->mctx, work, sizeof(*work));
|
||||
isc_loop_noteardown(work->loop, work->cancel_job);
|
||||
|
||||
isc_mem_put(work->loop->mctx, work, sizeof(*work));
|
||||
}
|
||||
|
||||
static void
|
||||
isc__work_cancel(void *arg) {
|
||||
isc_work_t *work = (isc_work_t *)arg;
|
||||
int r = uv_cancel((uv_req_t *)&work->work);
|
||||
UV_RUNTIME_CHECK(uv_cancel, r);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -53,15 +62,17 @@ isc_queue_work(isc_loop_t *loop, isc_work_cb work_cb,
|
||||
|
||||
work = isc_mem_get(loop->mctx, sizeof(*work));
|
||||
*work = (isc_work_t){
|
||||
.loop = loop,
|
||||
.work_cb = work_cb,
|
||||
.after_work_cb = after_work_cb,
|
||||
.cbarg = cbarg,
|
||||
};
|
||||
isc_mem_attach(loop->mctx, &work->mctx);
|
||||
|
||||
uv_req_set_data((uv_req_t *)&work->work, work);
|
||||
|
||||
r = uv_queue_work(&loop->loop, &work->work, isc__work_cb,
|
||||
isc__after_work_cb);
|
||||
UV_RUNTIME_CHECK(uv_queue_work, r);
|
||||
|
||||
work->cancel_job = isc_loop_teardown(loop, isc__work_cancel, work);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user