uv-compat.h revision 1.2
1/*	$NetBSD: uv-compat.h,v 1.2 2020/05/24 19:46:27 christos Exp $	*/
2
3/*
4 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 *
10 * See the COPYRIGHT file distributed with this work for additional
11 * information regarding copyright ownership.
12 */
13
14#pragma once
15#include <uv.h>
16
17/*
18 * These functions were introduced in newer libuv, but we still
19 * want BIND9 compile on older ones so we emulate them.
20 * They're inline to avoid conflicts when running with a newer
21 * library version.
22 */
23
24#ifndef HAVE_UV_HANDLE_GET_DATA
25static inline void *
26uv_handle_get_data(const uv_handle_t *handle) {
27	return (handle->data);
28}
29#endif /* ifndef HAVE_UV_HANDLE_GET_DATA */
30
31#ifndef HAVE_UV_HANDLE_SET_DATA
32static inline void
33uv_handle_set_data(uv_handle_t *handle, void *data) {
34	handle->data = data;
35}
36#endif /* ifndef HAVE_UV_HANDLE_SET_DATA */
37
38#ifdef HAVE_UV_IMPORT
39
40#define isc_uv_stream_info_t uv_stream_info_t
41#define isc_uv_export	     uv_export
42#define isc_uv_import	     uv_import
43
44#else
45
46/*
47 * These functions are not available in libuv, but they're very internal
48 * to libuv. We should try to get them merged upstream.
49 */
50
51/*
52 * A sane way to pass listening TCP socket to child threads, without using
53 * IPC (as the libuv example shows) but a version of the uv_export() and
54 * uv_import() functions that were unfortunately removed from libuv.
55 * This is based on the original libuv code.
56 */
57
58typedef struct isc_uv_stream_info_s isc_uv_stream_info_t;
59
60struct isc_uv_stream_info_s {
61	uv_handle_type type;
62#ifdef WIN32
63	WSAPROTOCOL_INFOW socket_info;
64#else  /* ifdef WIN32 */
65	int fd;
66#endif /* ifdef WIN32 */
67};
68
69int
70isc_uv_export(uv_stream_t *stream, isc_uv_stream_info_t *info);
71/*%<
72 * Exports uv_stream_t as isc_uv_stream_info_t value, which could
73 * be used to initialize shared streams within the same process.
74 */
75
76int
77isc_uv_import(uv_stream_t *stream, isc_uv_stream_info_t *info);
78/*%<
79 * Imports uv_stream_info_t value into uv_stream_t to initialize a
80 * shared stream.
81 */
82
83#endif
84