uv-compat.h revision 1.4
1/* $NetBSD: uv-compat.h,v 1.4 2021/08/19 11:50:18 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 https://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#define UV_VERSION(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) 25 26#if UV_VERSION_HEX < UV_VERSION(1, 19, 0) 27static inline void * 28uv_handle_get_data(const uv_handle_t *handle) { 29 return (handle->data); 30} 31 32static inline void 33uv_handle_set_data(uv_handle_t *handle, void *data) { 34 handle->data = data; 35} 36 37static inline void * 38uv_req_get_data(const uv_req_t *req) { 39 return (req->data); 40} 41 42static inline void 43uv_req_set_data(uv_req_t *req, void *data) { 44 req->data = data; 45} 46#endif /* UV_VERSION_HEX < UV_VERSION(1, 19, 0) */ 47 48#if UV_VERSION_HEX < UV_VERSION(1, 34, 0) 49#define uv_sleep(msec) usleep(msec * 1000) 50#endif /* UV_VERSION_HEX < UV_VERSION(1, 34, 0) */ 51 52#if UV_VERSION_HEX < UV_VERSION(1, 27, 0) 53int 54isc_uv_udp_connect(uv_udp_t *handle, const struct sockaddr *addr); 55/*%< 56 * Associate the UDP handle to a remote address and port, so every message sent 57 * by this handle is automatically sent to that destination. 58 * 59 * NOTE: This is just a limited shim for uv_udp_connect() as it requires the 60 * handle to be bound. 61 */ 62#else /* UV_VERSION_HEX < UV_VERSION(1, 27, 0) */ 63#define isc_uv_udp_connect uv_udp_connect 64#endif /* UV_VERSION_HEX < UV_VERSION(1, 27, 0) */ 65 66#if UV_VERSION_HEX < UV_VERSION(1, 12, 0) 67#include <stdlib.h> 68#include <string.h> 69 70static inline int 71uv_os_getenv(const char *name, char *buffer, size_t *size) { 72 size_t len; 73 char *buf = getenv(name); 74 75 if (buf == NULL) { 76 return (UV_ENOENT); 77 } 78 79 len = strlen(buf) + 1; 80 if (len > *size) { 81 *size = len; 82 return (UV_ENOBUFS); 83 } 84 85 *size = len; 86 memmove(buffer, buf, len); 87 88 return (0); 89} 90 91#define uv_os_setenv(name, value) setenv(name, value, 0) 92#endif /* UV_VERSION_HEX < UV_VERSION(1, 12, 0) */ 93 94int 95isc_uv_udp_freebind(uv_udp_t *handle, const struct sockaddr *addr, 96 unsigned int flags); 97 98int 99isc_uv_tcp_freebind(uv_tcp_t *handle, const struct sockaddr *addr, 100 unsigned int flags); 101