Home | History | Annotate | Line # | Download | only in isc
      1 /*	$NetBSD: uv.h,v 1.2 2025/01/26 16:25:43 christos Exp $	*/
      2 
      3 /*
      4  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
      5  *
      6  * SPDX-License-Identifier: MPL-2.0
      7  *
      8  * This Source Code Form is subject to the terms of the Mozilla Public
      9  * License, v. 2.0. If a copy of the MPL was not distributed with this
     10  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
     11  *
     12  * See the COPYRIGHT file distributed with this work for additional
     13  * information regarding copyright ownership.
     14  */
     15 
     16 #pragma once
     17 
     18 #include <stdbool.h>
     19 #include <uv.h>
     20 
     21 #include <isc/result.h>
     22 #include <isc/tid.h>
     23 
     24 #define UV_VERSION(major, minor, patch) ((major << 16) | (minor << 8) | (patch))
     25 
     26 /*
     27  * Copied verbatim from libuv/src/version.c
     28  */
     29 
     30 #define UV_STRINGIFY(v)	       UV_STRINGIFY_HELPER(v)
     31 #define UV_STRINGIFY_HELPER(v) #v
     32 
     33 #define UV_VERSION_STRING_BASE         \
     34 	UV_STRINGIFY(UV_VERSION_MAJOR) \
     35 	"." UV_STRINGIFY(UV_VERSION_MINOR) "." UV_STRINGIFY(UV_VERSION_PATCH)
     36 
     37 #if UV_VERSION_IS_RELEASE
     38 #define UV_VERSION_STRING UV_VERSION_STRING_BASE
     39 #else
     40 #define UV_VERSION_STRING UV_VERSION_STRING_BASE "-" UV_VERSION_SUFFIX
     41 #endif
     42 
     43 #if !defined(UV__ERR)
     44 #define UV__ERR(x) (-(x))
     45 #endif
     46 
     47 /*
     48  * These are used with all versions of libuv:
     49  */
     50 
     51 #define UV_RUNTIME_CHECK(func, ret)                                      \
     52 	if (ret != 0) {                                                  \
     53 		FATAL_ERROR("%s failed: %s\n", #func, uv_strerror(ret)); \
     54 	}
     55 
     56 #define isc_uverr2result(x) \
     57 	isc__uverr2result(x, true, __FILE__, __LINE__, __func__)
     58 isc_result_t
     59 isc__uverr2result(int uverr, bool dolog, const char *file, unsigned int line,
     60 		  const char *func);
     61 /*%<
     62  * Convert a libuv error value into an isc_result_t.  The
     63  * list of supported error values is not complete; new users
     64  * of this function should add any expected errors that are
     65  * not already there.
     66  */
     67 
     68 /**
     69  * Type-casting helpers
     70  */
     71 
     72 #define uv_handle_set_data(handle, data) \
     73 	uv_handle_set_data((uv_handle_t *)(handle), (data))
     74 #define uv_handle_get_data(handle) uv_handle_get_data((uv_handle_t *)(handle))
     75 #define uv_close(handle, close_cb) uv_close((uv_handle_t *)handle, close_cb)
     76 
     77 #if UV_TRACE_INIT
     78 
     79 #define uv_idle_init(loop, idle)                                          \
     80 	({                                                                \
     81 		int __r = uv_idle_init(loop, idle);                       \
     82 		fprintf(stderr, "%" PRIu32 ":%s_:uv_idle_init(%p, %p)\n", \
     83 			isc_tid(), __func__, loop, idle);                 \
     84 		__r;                                                      \
     85 	})
     86 
     87 #define uv_timer_init(loop, timer)                                         \
     88 	({                                                                 \
     89 		int __r = uv_timer_init(loop, timer);                      \
     90 		fprintf(stderr, "%" PRIu32 ":%s_:uv_timer_init(%p, %p)\n", \
     91 			isc_tid(), __func__, loop, timer);                 \
     92 		__r;                                                       \
     93 	})
     94 
     95 #define uv_async_init(loop, async, async_cb)                                   \
     96 	({                                                                     \
     97 		int __r = uv_async_init(loop, async, async_cb);                \
     98 		fprintf(stderr, "%" PRIu32 ":%s_:uv_timer_init(%p, %p, %p)\n", \
     99 			isc_tid(), __func__, loop, async, async_cb);           \
    100 		__r;                                                           \
    101 	})
    102 
    103 #define uv_close(handle, close_cb)                                    \
    104 	({                                                            \
    105 		uv_close(handle, close_cb);                           \
    106 		fprintf(stderr, "%" PRIu32 ":%s_:uv_close(%p, %p)\n", \
    107 			isc_tid(), __func__, handle, close_cb);       \
    108 	})
    109 
    110 #endif
    111 
    112 /*
    113  * Internal
    114  */
    115 
    116 void
    117 isc__uv_initialize(void);
    118 void
    119 isc__uv_shutdown(void);
    120 void
    121 isc__uv_setdestroycheck(bool check);
    122