Commit 5a65ec0a authored by Witold Krecicki's avatar Witold Krecicki Committed by Evan Hunt

Add uv_handle_{get,set}_data functions that's absent in pre-1.19 libuv to make code clearer.

This might be removed when we stop supporting older libuv versions.
parent bc5aae15
...@@ -465,6 +465,12 @@ ...@@ -465,6 +465,12 @@
/* Define to 1 if you have the `usleep' function. */ /* Define to 1 if you have the `usleep' function. */
#undef HAVE_USLEEP #undef HAVE_USLEEP
/* Define to 1 if you have the `uv_handle_get_data' function. */
#undef HAVE_UV_HANDLE_GET_DATA
/* Define to 1 if you have the `uv_handle_set_data' function. */
#undef HAVE_UV_HANDLE_SET_DATA
/* Use zlib library */ /* Use zlib library */
#undef HAVE_ZLIB #undef HAVE_ZLIB
......
...@@ -15943,6 +15943,21 @@ fi ...@@ -15943,6 +15943,21 @@ fi
CFLAGS="$CFLAGS $LIBUV_CFLAGS" CFLAGS="$CFLAGS $LIBUV_CFLAGS"
LIBS="$LIBS $LIBUV_LIBS" LIBS="$LIBS $LIBUV_LIBS"
# Those functions are only provided in newer versions of libuv, we'll be emulating them
# for now
for ac_func in uv_handle_get_data uv_handle_set_data
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
cat >>confdefs.h <<_ACEOF
#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
_ACEOF
fi
done
# #
# flockfile is usually provided by pthreads # flockfile is usually provided by pthreads
# #
......
...@@ -663,6 +663,10 @@ AX_SAVE_FLAGS([libuv]) ...@@ -663,6 +663,10 @@ AX_SAVE_FLAGS([libuv])
CFLAGS="$CFLAGS $LIBUV_CFLAGS" CFLAGS="$CFLAGS $LIBUV_CFLAGS"
LIBS="$LIBS $LIBUV_LIBS" LIBS="$LIBS $LIBUV_LIBS"
# Those functions are only provided in newer versions of libuv, we'll be emulating them
# for now
AC_CHECK_FUNCS([uv_handle_get_data uv_handle_set_data])
# #
# flockfile is usually provided by pthreads # flockfile is usually provided by pthreads
# #
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <isc/thread.h> #include <isc/thread.h>
#include <isc/util.h> #include <isc/util.h>
#include "uv-compat.h"
#include "netmgr-int.h" #include "netmgr-int.h"
/* /*
...@@ -827,7 +828,7 @@ isc__nmsocket_init(isc_nmsocket_t *sock, isc_nm_t *mgr, ...@@ -827,7 +828,7 @@ isc__nmsocket_init(isc_nmsocket_t *sock, isc_nm_t *mgr,
void void
isc__nm_alloc_cb(uv_handle_t *handle, size_t size, uv_buf_t *buf) { isc__nm_alloc_cb(uv_handle_t *handle, size_t size, uv_buf_t *buf) {
isc_nmsocket_t *sock = (isc_nmsocket_t *) handle->data; isc_nmsocket_t *sock = uv_handle_get_data(handle);
isc__networker_t *worker = NULL; isc__networker_t *worker = NULL;
REQUIRE(VALID_NMSOCK(sock)); REQUIRE(VALID_NMSOCK(sock));
...@@ -1208,7 +1209,7 @@ shutdown_walk_cb(uv_handle_t *handle, void *arg) { ...@@ -1208,7 +1209,7 @@ shutdown_walk_cb(uv_handle_t *handle, void *arg) {
switch(handle->type) { switch(handle->type) {
case UV_TCP: case UV_TCP:
isc__nm_tcp_shutdown((isc_nmsocket_t *) handle->data); isc__nm_tcp_shutdown(uv_handle_get_data(handle));
break; break;
default: default:
break; break;
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <isc/thread.h> #include <isc/thread.h>
#include <isc/util.h> #include <isc/util.h>
#include "uv-compat.h"
#include "netmgr-int.h" #include "netmgr-int.h"
static int static int
...@@ -86,7 +87,7 @@ tcp_connect_direct(isc_nmsocket_t *sock, isc__nm_uvreq_t *req) { ...@@ -86,7 +87,7 @@ tcp_connect_direct(isc_nmsocket_t *sock, isc__nm_uvreq_t *req) {
return (r); return (r);
} }
} }
sock->uv_handle.tcp.data = sock; uv_handle_set_data(&sock->uv_handle.handle, sock);
r = uv_tcp_connect(&req->uv_req.connect, &sock->uv_handle.tcp, r = uv_tcp_connect(&req->uv_req.connect, &sock->uv_handle.tcp,
&req->peer.type.sa, tcp_connect_cb); &req->peer.type.sa, tcp_connect_cb);
return (r); return (r);
...@@ -113,7 +114,8 @@ isc__nm_async_tcpconnect(isc__networker_t *worker, isc__netievent_t *ievent0) { ...@@ -113,7 +114,8 @@ isc__nm_async_tcpconnect(isc__networker_t *worker, isc__netievent_t *ievent0) {
static void static void
tcp_connect_cb(uv_connect_t *uvreq, int status) { tcp_connect_cb(uv_connect_t *uvreq, int status) {
isc__nm_uvreq_t *req = (isc__nm_uvreq_t *) uvreq->data; isc__nm_uvreq_t *req = (isc__nm_uvreq_t *) uvreq->data;
isc_nmsocket_t *sock = uvreq->handle->data; isc_nmsocket_t *sock;
sock = uv_handle_get_data((uv_handle_t *) uvreq->handle);
REQUIRE(VALID_UVREQ(req)); REQUIRE(VALID_UVREQ(req));
...@@ -211,8 +213,11 @@ isc__nm_async_tcplisten(isc__networker_t *worker, isc__netievent_t *ievent0) { ...@@ -211,8 +213,11 @@ isc__nm_async_tcplisten(isc__networker_t *worker, isc__netievent_t *ievent0) {
return; return;
} }
uv_tcp_bind(&sock->uv_handle.tcp, &sock->iface->addr.type.sa, 0); r = uv_tcp_bind(&sock->uv_handle.tcp, &sock->iface->addr.type.sa, 0);
sock->uv_handle.tcp.data = sock; if (r != 0) {
return;
}
uv_handle_set_data(&sock->uv_handle.handle, sock);
/* /*
* This is not properly documented in libuv, and the example * This is not properly documented in libuv, and the example
* (benchmark-multi-accept) is wrong: * (benchmark-multi-accept) is wrong:
...@@ -223,7 +228,7 @@ isc__nm_async_tcplisten(isc__networker_t *worker, isc__netievent_t *ievent0) { ...@@ -223,7 +228,7 @@ isc__nm_async_tcplisten(isc__networker_t *worker, isc__netievent_t *ievent0) {
*/ */
r = uv_pipe_init(&worker->loop, &sock->ipc, 0); r = uv_pipe_init(&worker->loop, &sock->ipc, 0);
INSIST(r == 0); INSIST(r == 0);
sock->ipc.data = sock; uv_handle_set_data((uv_handle_t *)&sock->ipc, sock);
r = uv_pipe_bind(&sock->ipc, sock->ipc_pipe_name); r = uv_pipe_bind(&sock->ipc, sock->ipc_pipe_name);
INSIST(r == 0); INSIST(r == 0);
r = uv_listen((uv_stream_t *) &sock->ipc, sock->nchildren, r = uv_listen((uv_stream_t *) &sock->ipc, sock->nchildren,
...@@ -274,7 +279,7 @@ static void ...@@ -274,7 +279,7 @@ static void
ipc_connection_cb(uv_stream_t *stream, int status) { ipc_connection_cb(uv_stream_t *stream, int status) {
int r; int r;
REQUIRE(status == 0); REQUIRE(status == 0);
isc_nmsocket_t *sock = stream->data; isc_nmsocket_t *sock = uv_handle_get_data((uv_handle_t *) stream);
isc__networker_t *worker = &sock->mgr->workers[isc_nm_tid()]; isc__networker_t *worker = &sock->mgr->workers[isc_nm_tid()];
isc__nm_uvreq_t *nreq = isc__nm_uvreq_get(sock->mgr, sock); isc__nm_uvreq_t *nreq = isc__nm_uvreq_get(sock->mgr, sock);
/* /*
...@@ -283,7 +288,7 @@ ipc_connection_cb(uv_stream_t *stream, int status) { ...@@ -283,7 +288,7 @@ ipc_connection_cb(uv_stream_t *stream, int status) {
*/ */
nreq->uvbuf = uv_buf_init((char *)nreq, 1); nreq->uvbuf = uv_buf_init((char *)nreq, 1);
uv_pipe_init(&worker->loop, &nreq->pipe, 1); uv_pipe_init(&worker->loop, &nreq->pipe, 1);
nreq->pipe.data = nreq; uv_handle_set_data((uv_handle_t *)&nreq->pipe, nreq);
/* Failure here is critical */ /* Failure here is critical */
r = uv_accept((uv_stream_t *) &sock->ipc, r = uv_accept((uv_stream_t *) &sock->ipc,
...@@ -315,7 +320,7 @@ ipc_write_cb(uv_write_t* uvreq, int status) { ...@@ -315,7 +320,7 @@ ipc_write_cb(uv_write_t* uvreq, int status) {
static void static void
parent_pipe_close_cb(uv_handle_t *handle) { parent_pipe_close_cb(uv_handle_t *handle) {
isc__nm_uvreq_t *req = handle->data; isc__nm_uvreq_t *req = uv_handle_get_data(handle);
isc__nm_uvreq_put(&req, req->sock); isc__nm_uvreq_put(&req, req->sock);
} }
...@@ -331,7 +336,7 @@ isc__nm_async_tcpchildlisten(isc__networker_t *worker, isc__netievent_t *ievent0 ...@@ -331,7 +336,7 @@ isc__nm_async_tcpchildlisten(isc__networker_t *worker, isc__netievent_t *ievent0
r = uv_pipe_init(&worker->loop, &sock->ipc, 1); r = uv_pipe_init(&worker->loop, &sock->ipc, 1);
INSIST(r == 0); INSIST(r == 0);
sock->ipc.data = sock; uv_handle_set_data((uv_handle_t *) &sock->ipc, sock);
isc__nm_uvreq_t * req = isc__nm_uvreq_get(sock->mgr, sock); isc__nm_uvreq_t * req = isc__nm_uvreq_get(sock->mgr, sock);
uv_pipe_connect(&req->uv_req.connect, uv_pipe_connect(&req->uv_req.connect,
...@@ -358,7 +363,7 @@ static void ...@@ -358,7 +363,7 @@ static void
childlisten_read_cb(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) { childlisten_read_cb(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) {
UNUSED(nread); UNUSED(nread);
int r; int r;
isc_nmsocket_t *sock = stream->data; isc_nmsocket_t *sock = uv_handle_get_data((uv_handle_t *) stream);
REQUIRE(VALID_NMSOCK(sock)); REQUIRE(VALID_NMSOCK(sock));
REQUIRE(buf != NULL); REQUIRE(buf != NULL);
...@@ -368,7 +373,7 @@ childlisten_read_cb(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) { ...@@ -368,7 +373,7 @@ childlisten_read_cb(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) {
isc__nm_free_uvbuf(sock, buf); isc__nm_free_uvbuf(sock, buf);
isc__networker_t * worker = &sock->mgr->workers[isc_nm_tid()]; isc__networker_t * worker = &sock->mgr->workers[isc_nm_tid()];
uv_tcp_init(&worker->loop, (uv_tcp_t*) &sock->uv_handle.tcp); uv_tcp_init(&worker->loop, (uv_tcp_t*) &sock->uv_handle.tcp);
sock->uv_handle.tcp.data = sock; uv_handle_set_data(&sock->uv_handle.handle, sock);
uv_accept(stream, &sock->uv_handle.stream); uv_accept(stream, &sock->uv_handle.stream);
r = uv_listen((uv_stream_t *) &sock->uv_handle.tcp, sock->backlog, r = uv_listen((uv_stream_t *) &sock->uv_handle.tcp, sock->backlog,
tcp_connection_cb); tcp_connection_cb);
...@@ -489,7 +494,7 @@ isc__nm_async_tcpstopchildlisten(isc__networker_t *worker, ...@@ -489,7 +494,7 @@ isc__nm_async_tcpstopchildlisten(isc__networker_t *worker,
*/ */
static void static void
tcp_listenclose_cb(uv_handle_t *handle) { tcp_listenclose_cb(uv_handle_t *handle) {
isc_nmsocket_t *sock = handle->data; isc_nmsocket_t *sock = uv_handle_get_data(handle);
isc_mutex_t * lock = (sock->parent != NULL) ? isc_mutex_t * lock = (sock->parent != NULL) ?
&sock->parent->lock : &sock->lock; &sock->parent->lock : &sock->lock;
LOCK(lock); LOCK(lock);
...@@ -502,7 +507,7 @@ tcp_listenclose_cb(uv_handle_t *handle) { ...@@ -502,7 +507,7 @@ tcp_listenclose_cb(uv_handle_t *handle) {
static void static void
readtimeout_cb(uv_timer_t *handle) { readtimeout_cb(uv_timer_t *handle) {
isc_nmsocket_t *sock = (isc_nmsocket_t *) handle->data; isc_nmsocket_t *sock = uv_handle_get_data((uv_handle_t *)handle);
REQUIRE(VALID_NMSOCK(sock)); REQUIRE(VALID_NMSOCK(sock));
REQUIRE(sock->tid == isc_nm_tid()); REQUIRE(sock->tid == isc_nm_tid());
...@@ -563,7 +568,7 @@ isc__nm_async_startread(isc__networker_t *worker, isc__netievent_t *ievent0) { ...@@ -563,7 +568,7 @@ isc__nm_async_startread(isc__networker_t *worker, isc__netievent_t *ievent0) {
if (sock->read_timeout != 0) { if (sock->read_timeout != 0) {
if (!sock->timer_initialized) { if (!sock->timer_initialized) {
uv_timer_init(&worker->loop, &sock->timer); uv_timer_init(&worker->loop, &sock->timer);
sock->timer.data = sock; uv_handle_set_data((uv_handle_t *)&sock->timer, sock);
sock->timer_initialized = true; sock->timer_initialized = true;
} }
uv_timer_start(&sock->timer, readtimeout_cb, uv_timer_start(&sock->timer, readtimeout_cb,
...@@ -644,7 +649,7 @@ isc_nm_resumeread(isc_nmsocket_t *sock) { ...@@ -644,7 +649,7 @@ isc_nm_resumeread(isc_nmsocket_t *sock) {
static void static void
read_cb(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) { read_cb(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) {
isc_nmsocket_t *sock = stream->data; isc_nmsocket_t *sock = uv_handle_get_data((uv_handle_t*) stream);
REQUIRE(VALID_NMSOCK(sock)); REQUIRE(VALID_NMSOCK(sock));
REQUIRE(buf != NULL); REQUIRE(buf != NULL);
...@@ -759,7 +764,7 @@ accept_connection(isc_nmsocket_t *ssock) { ...@@ -759,7 +764,7 @@ accept_connection(isc_nmsocket_t *ssock) {
static void static void
tcp_connection_cb(uv_stream_t *server, int status) { tcp_connection_cb(uv_stream_t *server, int status) {
isc_nmsocket_t *ssock = server->data; isc_nmsocket_t *ssock = uv_handle_get_data((uv_handle_t*) server);
isc_result_t result; isc_result_t result;
UNUSED(status); UNUSED(status);
...@@ -875,7 +880,7 @@ tcp_send_direct(isc_nmsocket_t *sock, isc__nm_uvreq_t *req) { ...@@ -875,7 +880,7 @@ tcp_send_direct(isc_nmsocket_t *sock, isc__nm_uvreq_t *req) {
static void static void
tcp_close_cb(uv_handle_t *uvhandle) { tcp_close_cb(uv_handle_t *uvhandle) {
isc_nmsocket_t *sock = uvhandle->data; isc_nmsocket_t *sock = uv_handle_get_data(uvhandle);
REQUIRE(VALID_NMSOCK(sock)); REQUIRE(VALID_NMSOCK(sock));
...@@ -885,7 +890,7 @@ tcp_close_cb(uv_handle_t *uvhandle) { ...@@ -885,7 +890,7 @@ tcp_close_cb(uv_handle_t *uvhandle) {
static void static void
timer_close_cb(uv_handle_t *uvhandle) { timer_close_cb(uv_handle_t *uvhandle) {
isc_nmsocket_t *sock = uvhandle->data; isc_nmsocket_t *sock = uv_handle_get_data(uvhandle);
REQUIRE(VALID_NMSOCK(sock)); REQUIRE(VALID_NMSOCK(sock));
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <isc/thread.h> #include <isc/thread.h>
#include <isc/util.h> #include <isc/util.h>
#include "uv-compat.h"
#include "netmgr-int.h" #include "netmgr-int.h"
#define TCPDNS_CLIENTS_PER_CONN 23 #define TCPDNS_CLIENTS_PER_CONN 23
...@@ -76,7 +77,7 @@ alloc_dnsbuf(isc_nmsocket_t *sock, size_t len) { ...@@ -76,7 +77,7 @@ alloc_dnsbuf(isc_nmsocket_t *sock, size_t len) {
static void static void
timer_close_cb(uv_handle_t *handle) { timer_close_cb(uv_handle_t *handle) {
isc_nmsocket_t *sock = (isc_nmsocket_t *) handle->data; isc_nmsocket_t *sock = (isc_nmsocket_t *) uv_handle_get_data(handle);
INSIST(VALID_NMSOCK(sock)); INSIST(VALID_NMSOCK(sock));
sock->timer_initialized = false; sock->timer_initialized = false;
atomic_store(&sock->closed, true); atomic_store(&sock->closed, true);
...@@ -85,7 +86,8 @@ timer_close_cb(uv_handle_t *handle) { ...@@ -85,7 +86,8 @@ timer_close_cb(uv_handle_t *handle) {
static void static void
dnstcp_readtimeout(uv_timer_t *timer) { dnstcp_readtimeout(uv_timer_t *timer) {
isc_nmsocket_t *sock = (isc_nmsocket_t *) timer->data; isc_nmsocket_t *sock;
sock = (isc_nmsocket_t *) uv_handle_get_data((uv_handle_t *)timer);
REQUIRE(VALID_NMSOCK(sock)); REQUIRE(VALID_NMSOCK(sock));
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#include <isc/sockaddr.h> #include <isc/sockaddr.h>
#include <isc/thread.h> #include <isc/thread.h>
#include <isc/util.h> #include <isc/util.h>
#include "uv-compat.h"
#include "netmgr-int.h" #include "netmgr-int.h"
static isc_result_t static isc_result_t
...@@ -123,7 +125,7 @@ isc__nm_async_udplisten(isc__networker_t *worker, isc__netievent_t *ievent0) { ...@@ -123,7 +125,7 @@ isc__nm_async_udplisten(isc__networker_t *worker, isc__netievent_t *ievent0) {
REQUIRE(sock->parent != NULL); REQUIRE(sock->parent != NULL);
uv_udp_init(&worker->loop, &sock->uv_handle.udp); uv_udp_init(&worker->loop, &sock->uv_handle.udp);
sock->uv_handle.udp.data = NULL; uv_handle_set_data(&sock->uv_handle.handle, NULL);
isc_nmsocket_attach(sock, isc_nmsocket_attach(sock,
(isc_nmsocket_t **)&sock->uv_handle.udp.data); (isc_nmsocket_t **)&sock->uv_handle.udp.data);
...@@ -140,7 +142,7 @@ isc__nm_async_udplisten(isc__networker_t *worker, isc__netievent_t *ievent0) { ...@@ -140,7 +142,7 @@ isc__nm_async_udplisten(isc__networker_t *worker, isc__netievent_t *ievent0) {
static void static void
udp_close_cb(uv_handle_t *handle) { udp_close_cb(uv_handle_t *handle) {
isc_nmsocket_t *sock = handle->data; isc_nmsocket_t *sock = uv_handle_get_data(handle);
atomic_store(&sock->closed, true); atomic_store(&sock->closed, true);
isc_nmsocket_detach((isc_nmsocket_t **)&sock->uv_handle.udp.data); isc_nmsocket_detach((isc_nmsocket_t **)&sock->uv_handle.udp.data);
...@@ -271,7 +273,7 @@ udp_recv_cb(uv_udp_t *handle, ssize_t nrecv, const uv_buf_t *buf, ...@@ -271,7 +273,7 @@ udp_recv_cb(uv_udp_t *handle, ssize_t nrecv, const uv_buf_t *buf,
isc_sockaddr_t sockaddr; isc_sockaddr_t sockaddr;
isc_sockaddr_t localaddr; isc_sockaddr_t localaddr;
struct sockaddr_storage laddr; struct sockaddr_storage laddr;
isc_nmsocket_t *sock = (isc_nmsocket_t *) handle->data; isc_nmsocket_t *sock = uv_handle_get_data((uv_handle_t *)handle);
isc_region_t region; isc_region_t region;
uint32_t maxudp; uint32_t maxudp;
......
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
#pragma once
#include <uv.h>
/*
* Those functions were introduced in newer libuv, 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.
*/
#ifndef HAVE_UV_HANDLE_GET_DATA
static inline void*
uv_handle_get_data(const uv_handle_t* handle) {
return (handle->data);
}
#endif
#ifndef HAVE_UV_HANDLE_SET_DATA
static inline void
uv_handle_set_data(uv_handle_t* handle, void* data) {
handle->data = data;
};
#endif
...@@ -2258,6 +2258,7 @@ ...@@ -2258,6 +2258,7 @@
./lib/isc/netmgr/tcp.c C 2019 ./lib/isc/netmgr/tcp.c C 2019
./lib/isc/netmgr/tcpdns.c C 2019 ./lib/isc/netmgr/tcpdns.c C 2019
./lib/isc/netmgr/udp.c C 2019 ./lib/isc/netmgr/udp.c C 2019
./lib/isc/netmgr/uv-compat.h C 2019
./lib/isc/netmgr/uverr2result.c C 2019 ./lib/isc/netmgr/uverr2result.c C 2019
./lib/isc/netscope.c C 2002,2004,2005,2006,2007,2016,2018,2019 ./lib/isc/netscope.c C 2002,2004,2005,2006,2007,2016,2018,2019
./lib/isc/nonce.c C 2018,2019 ./lib/isc/nonce.c C 2018,2019
......
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