1e66f31c5Sopenharmony_ci/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2e66f31c5Sopenharmony_ci * 3e66f31c5Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy 4e66f31c5Sopenharmony_ci * of this software and associated documentation files (the "Software"), to 5e66f31c5Sopenharmony_ci * deal in the Software without restriction, including without limitation the 6e66f31c5Sopenharmony_ci * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7e66f31c5Sopenharmony_ci * sell copies of the Software, and to permit persons to whom the Software is 8e66f31c5Sopenharmony_ci * furnished to do so, subject to the following conditions: 9e66f31c5Sopenharmony_ci * 10e66f31c5Sopenharmony_ci * The above copyright notice and this permission notice shall be included in 11e66f31c5Sopenharmony_ci * all copies or substantial portions of the Software. 12e66f31c5Sopenharmony_ci * 13e66f31c5Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14e66f31c5Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15e66f31c5Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16e66f31c5Sopenharmony_ci * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17e66f31c5Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18e66f31c5Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19e66f31c5Sopenharmony_ci * IN THE SOFTWARE. 20e66f31c5Sopenharmony_ci */ 21e66f31c5Sopenharmony_ci 22e66f31c5Sopenharmony_ci#ifndef TASK_H_ 23e66f31c5Sopenharmony_ci#define TASK_H_ 24e66f31c5Sopenharmony_ci 25e66f31c5Sopenharmony_ci#include "uv.h" 26e66f31c5Sopenharmony_ci 27e66f31c5Sopenharmony_ci#include <stdio.h> 28e66f31c5Sopenharmony_ci#include <stddef.h> 29e66f31c5Sopenharmony_ci#include <stdlib.h> 30e66f31c5Sopenharmony_ci#include <string.h> 31e66f31c5Sopenharmony_ci#include <inttypes.h> 32e66f31c5Sopenharmony_ci#include <stdint.h> 33e66f31c5Sopenharmony_ci 34e66f31c5Sopenharmony_ci#if !defined(_WIN32) 35e66f31c5Sopenharmony_ci# include <sys/time.h> 36e66f31c5Sopenharmony_ci# include <sys/resource.h> /* setrlimit() */ 37e66f31c5Sopenharmony_ci#endif 38e66f31c5Sopenharmony_ci 39e66f31c5Sopenharmony_ci#ifdef __clang__ 40e66f31c5Sopenharmony_ci# pragma clang diagnostic ignored "-Wvariadic-macros" 41e66f31c5Sopenharmony_ci# pragma clang diagnostic ignored "-Wc99-extensions" 42e66f31c5Sopenharmony_ci#endif 43e66f31c5Sopenharmony_ci 44e66f31c5Sopenharmony_ci#ifdef __GNUC__ 45e66f31c5Sopenharmony_ci# pragma GCC diagnostic ignored "-Wvariadic-macros" 46e66f31c5Sopenharmony_ci#endif 47e66f31c5Sopenharmony_ci 48e66f31c5Sopenharmony_ci#define TEST_PORT 9123 49e66f31c5Sopenharmony_ci#define TEST_PORT_2 9124 50e66f31c5Sopenharmony_ci#define TEST_PORT_3 9125 51e66f31c5Sopenharmony_ci 52e66f31c5Sopenharmony_ci#ifdef _WIN32 53e66f31c5Sopenharmony_ci# define TEST_PIPENAME "\\\\.\\pipe\\uv-test" 54e66f31c5Sopenharmony_ci# define TEST_PIPENAME_2 "\\\\.\\pipe\\uv-test2" 55e66f31c5Sopenharmony_ci# define TEST_PIPENAME_3 "\\\\.\\pipe\\uv-test3" 56e66f31c5Sopenharmony_ci#else 57e66f31c5Sopenharmony_ci# define TEST_PIPENAME "/tmp/uv-test-sock" 58e66f31c5Sopenharmony_ci# define TEST_PIPENAME_2 "/tmp/uv-test-sock2" 59e66f31c5Sopenharmony_ci# define TEST_PIPENAME_3 "/tmp/uv-test-sock3" 60e66f31c5Sopenharmony_ci#endif 61e66f31c5Sopenharmony_ci 62e66f31c5Sopenharmony_ci#ifdef _WIN32 63e66f31c5Sopenharmony_ci# include <io.h> 64e66f31c5Sopenharmony_ci# ifndef S_IRUSR 65e66f31c5Sopenharmony_ci# define S_IRUSR _S_IREAD 66e66f31c5Sopenharmony_ci# endif 67e66f31c5Sopenharmony_ci# ifndef S_IWUSR 68e66f31c5Sopenharmony_ci# define S_IWUSR _S_IWRITE 69e66f31c5Sopenharmony_ci# endif 70e66f31c5Sopenharmony_ci#endif 71e66f31c5Sopenharmony_ci 72e66f31c5Sopenharmony_ci#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) 73e66f31c5Sopenharmony_ci 74e66f31c5Sopenharmony_ci#define container_of(ptr, type, member) \ 75e66f31c5Sopenharmony_ci ((type *) ((char *) (ptr) - offsetof(type, member))) 76e66f31c5Sopenharmony_ci 77e66f31c5Sopenharmony_citypedef enum { 78e66f31c5Sopenharmony_ci TCP = 0, 79e66f31c5Sopenharmony_ci UDP, 80e66f31c5Sopenharmony_ci PIPE 81e66f31c5Sopenharmony_ci} stream_type; 82e66f31c5Sopenharmony_ci 83e66f31c5Sopenharmony_ci/* Die with fatal error. */ 84e66f31c5Sopenharmony_ci#define FATAL(msg) \ 85e66f31c5Sopenharmony_ci do { \ 86e66f31c5Sopenharmony_ci fprintf(stderr, \ 87e66f31c5Sopenharmony_ci "Fatal error in %s on line %d: %s\n", \ 88e66f31c5Sopenharmony_ci __FILE__, \ 89e66f31c5Sopenharmony_ci __LINE__, \ 90e66f31c5Sopenharmony_ci msg); \ 91e66f31c5Sopenharmony_ci fflush(stderr); \ 92e66f31c5Sopenharmony_ci abort(); \ 93e66f31c5Sopenharmony_ci } while (0) 94e66f31c5Sopenharmony_ci 95e66f31c5Sopenharmony_ci/* Have our own assert, so we are sure it does not get optimized away in 96e66f31c5Sopenharmony_ci * a release build. 97e66f31c5Sopenharmony_ci */ 98e66f31c5Sopenharmony_ci#define ASSERT(expr) \ 99e66f31c5Sopenharmony_ci do { \ 100e66f31c5Sopenharmony_ci if (!(expr)) { \ 101e66f31c5Sopenharmony_ci fprintf(stderr, \ 102e66f31c5Sopenharmony_ci "Assertion failed in %s on line %d: %s\n", \ 103e66f31c5Sopenharmony_ci __FILE__, \ 104e66f31c5Sopenharmony_ci __LINE__, \ 105e66f31c5Sopenharmony_ci #expr); \ 106e66f31c5Sopenharmony_ci abort(); \ 107e66f31c5Sopenharmony_ci } \ 108e66f31c5Sopenharmony_ci } while (0) 109e66f31c5Sopenharmony_ci 110e66f31c5Sopenharmony_ci#define ASSERT_BASE(a, operator, b, type, conv) \ 111e66f31c5Sopenharmony_ci do { \ 112e66f31c5Sopenharmony_ci volatile type eval_a = (type) (a); \ 113e66f31c5Sopenharmony_ci volatile type eval_b = (type) (b); \ 114e66f31c5Sopenharmony_ci if (!(eval_a operator eval_b)) { \ 115e66f31c5Sopenharmony_ci fprintf(stderr, \ 116e66f31c5Sopenharmony_ci "Assertion failed in %s on line %d: `%s %s %s` " \ 117e66f31c5Sopenharmony_ci "(%"conv" %s %"conv")\n", \ 118e66f31c5Sopenharmony_ci __FILE__, \ 119e66f31c5Sopenharmony_ci __LINE__, \ 120e66f31c5Sopenharmony_ci #a, \ 121e66f31c5Sopenharmony_ci #operator, \ 122e66f31c5Sopenharmony_ci #b, \ 123e66f31c5Sopenharmony_ci eval_a, \ 124e66f31c5Sopenharmony_ci #operator, \ 125e66f31c5Sopenharmony_ci eval_b); \ 126e66f31c5Sopenharmony_ci abort(); \ 127e66f31c5Sopenharmony_ci } \ 128e66f31c5Sopenharmony_ci } while (0) 129e66f31c5Sopenharmony_ci 130e66f31c5Sopenharmony_ci#define ASSERT_BASE_STR(expr, a, operator, b, type, conv) \ 131e66f31c5Sopenharmony_ci do { \ 132e66f31c5Sopenharmony_ci if (!(expr)) { \ 133e66f31c5Sopenharmony_ci fprintf(stderr, \ 134e66f31c5Sopenharmony_ci "Assertion failed in %s on line %d: `%s %s %s` " \ 135e66f31c5Sopenharmony_ci "(%"conv" %s %"conv")\n", \ 136e66f31c5Sopenharmony_ci __FILE__, \ 137e66f31c5Sopenharmony_ci __LINE__, \ 138e66f31c5Sopenharmony_ci #a, \ 139e66f31c5Sopenharmony_ci #operator, \ 140e66f31c5Sopenharmony_ci #b, \ 141e66f31c5Sopenharmony_ci (type)a, \ 142e66f31c5Sopenharmony_ci #operator, \ 143e66f31c5Sopenharmony_ci (type)b); \ 144e66f31c5Sopenharmony_ci abort(); \ 145e66f31c5Sopenharmony_ci } \ 146e66f31c5Sopenharmony_ci } while (0) 147e66f31c5Sopenharmony_ci 148e66f31c5Sopenharmony_ci#define ASSERT_BASE_LEN(expr, a, operator, b, conv, len) \ 149e66f31c5Sopenharmony_ci do { \ 150e66f31c5Sopenharmony_ci if (!(expr)) { \ 151e66f31c5Sopenharmony_ci fprintf(stderr, \ 152e66f31c5Sopenharmony_ci "Assertion failed in %s on line %d: `%s %s %s` " \ 153e66f31c5Sopenharmony_ci "(%.*"#conv" %s %.*"#conv")\n", \ 154e66f31c5Sopenharmony_ci __FILE__, \ 155e66f31c5Sopenharmony_ci __LINE__, \ 156e66f31c5Sopenharmony_ci #a, \ 157e66f31c5Sopenharmony_ci #operator, \ 158e66f31c5Sopenharmony_ci #b, \ 159e66f31c5Sopenharmony_ci (int)len, \ 160e66f31c5Sopenharmony_ci a, \ 161e66f31c5Sopenharmony_ci #operator, \ 162e66f31c5Sopenharmony_ci (int)len, \ 163e66f31c5Sopenharmony_ci b); \ 164e66f31c5Sopenharmony_ci abort(); \ 165e66f31c5Sopenharmony_ci } \ 166e66f31c5Sopenharmony_ci } while (0) 167e66f31c5Sopenharmony_ci 168e66f31c5Sopenharmony_ci#define ASSERT_BASE_HEX(expr, a, operator, b, size) \ 169e66f31c5Sopenharmony_ci do { \ 170e66f31c5Sopenharmony_ci if (!(expr)) { \ 171e66f31c5Sopenharmony_ci int i; \ 172e66f31c5Sopenharmony_ci unsigned char* a_ = (unsigned char*)a; \ 173e66f31c5Sopenharmony_ci unsigned char* b_ = (unsigned char*)b; \ 174e66f31c5Sopenharmony_ci fprintf(stderr, \ 175e66f31c5Sopenharmony_ci "Assertion failed in %s on line %d: `%s %s %s` (", \ 176e66f31c5Sopenharmony_ci __FILE__, \ 177e66f31c5Sopenharmony_ci __LINE__, \ 178e66f31c5Sopenharmony_ci #a, \ 179e66f31c5Sopenharmony_ci #operator, \ 180e66f31c5Sopenharmony_ci #b); \ 181e66f31c5Sopenharmony_ci for (i = 0; i < size; ++i) { \ 182e66f31c5Sopenharmony_ci if (i > 0) fprintf(stderr, ":"); \ 183e66f31c5Sopenharmony_ci fprintf(stderr, "%02X", a_[i]); \ 184e66f31c5Sopenharmony_ci } \ 185e66f31c5Sopenharmony_ci fprintf(stderr, " %s ", #operator); \ 186e66f31c5Sopenharmony_ci for (i = 0; i < size; ++i) { \ 187e66f31c5Sopenharmony_ci if (i > 0) fprintf(stderr, ":"); \ 188e66f31c5Sopenharmony_ci fprintf(stderr, "%02X", b_[i]); \ 189e66f31c5Sopenharmony_ci } \ 190e66f31c5Sopenharmony_ci fprintf(stderr, ")\n"); \ 191e66f31c5Sopenharmony_ci abort(); \ 192e66f31c5Sopenharmony_ci } \ 193e66f31c5Sopenharmony_ci } while (0) 194e66f31c5Sopenharmony_ci 195e66f31c5Sopenharmony_ci#define ASSERT_EQ(a, b) ASSERT_BASE(a, ==, b, int64_t, PRId64) 196e66f31c5Sopenharmony_ci#define ASSERT_GE(a, b) ASSERT_BASE(a, >=, b, int64_t, PRId64) 197e66f31c5Sopenharmony_ci#define ASSERT_GT(a, b) ASSERT_BASE(a, >, b, int64_t, PRId64) 198e66f31c5Sopenharmony_ci#define ASSERT_LE(a, b) ASSERT_BASE(a, <=, b, int64_t, PRId64) 199e66f31c5Sopenharmony_ci#define ASSERT_LT(a, b) ASSERT_BASE(a, <, b, int64_t, PRId64) 200e66f31c5Sopenharmony_ci#define ASSERT_NE(a, b) ASSERT_BASE(a, !=, b, int64_t, PRId64) 201e66f31c5Sopenharmony_ci#define ASSERT_OK(a) ASSERT_BASE(a, ==, 0, int64_t, PRId64) 202e66f31c5Sopenharmony_ci 203e66f31c5Sopenharmony_ci#define ASSERT_UINT64_EQ(a, b) ASSERT_BASE(a, ==, b, uint64_t, PRIu64) 204e66f31c5Sopenharmony_ci#define ASSERT_UINT64_GE(a, b) ASSERT_BASE(a, >=, b, uint64_t, PRIu64) 205e66f31c5Sopenharmony_ci#define ASSERT_UINT64_GT(a, b) ASSERT_BASE(a, >, b, uint64_t, PRIu64) 206e66f31c5Sopenharmony_ci#define ASSERT_UINT64_LE(a, b) ASSERT_BASE(a, <=, b, uint64_t, PRIu64) 207e66f31c5Sopenharmony_ci#define ASSERT_UINT64_LT(a, b) ASSERT_BASE(a, <, b, uint64_t, PRIu64) 208e66f31c5Sopenharmony_ci#define ASSERT_UINT64_NE(a, b) ASSERT_BASE(a, !=, b, uint64_t, PRIu64) 209e66f31c5Sopenharmony_ci 210e66f31c5Sopenharmony_ci#define ASSERT_DOUBLE_EQ(a, b) ASSERT_BASE(a, ==, b, double, "f") 211e66f31c5Sopenharmony_ci#define ASSERT_DOUBLE_GE(a, b) ASSERT_BASE(a, >=, b, double, "f") 212e66f31c5Sopenharmony_ci#define ASSERT_DOUBLE_GT(a, b) ASSERT_BASE(a, >, b, double, "f") 213e66f31c5Sopenharmony_ci#define ASSERT_DOUBLE_LE(a, b) ASSERT_BASE(a, <=, b, double, "f") 214e66f31c5Sopenharmony_ci#define ASSERT_DOUBLE_LT(a, b) ASSERT_BASE(a, <, b, double, "f") 215e66f31c5Sopenharmony_ci#define ASSERT_DOUBLE_NE(a, b) ASSERT_BASE(a, !=, b, double, "f") 216e66f31c5Sopenharmony_ci 217e66f31c5Sopenharmony_ci#define ASSERT_STR_EQ(a, b) \ 218e66f31c5Sopenharmony_ci ASSERT_BASE_STR(strcmp(a, b) == 0, a, == , b, char*, "s") 219e66f31c5Sopenharmony_ci 220e66f31c5Sopenharmony_ci#define ASSERT_STR_NE(a, b) \ 221e66f31c5Sopenharmony_ci ASSERT_BASE_STR(strcmp(a, b) != 0, a, !=, b, char*, "s") 222e66f31c5Sopenharmony_ci 223e66f31c5Sopenharmony_ci#define ASSERT_MEM_EQ(a, b, size) \ 224e66f31c5Sopenharmony_ci ASSERT_BASE_LEN(memcmp(a, b, size) == 0, a, ==, b, s, size) 225e66f31c5Sopenharmony_ci 226e66f31c5Sopenharmony_ci#define ASSERT_MEM_NE(a, b, size) \ 227e66f31c5Sopenharmony_ci ASSERT_BASE_LEN(memcmp(a, b, size) != 0, a, !=, b, s, size) 228e66f31c5Sopenharmony_ci 229e66f31c5Sopenharmony_ci#define ASSERT_MEM_HEX_EQ(a, b, size) \ 230e66f31c5Sopenharmony_ci ASSERT_BASE_HEX(memcmp(a, b, size) == 0, a, ==, b, size) 231e66f31c5Sopenharmony_ci 232e66f31c5Sopenharmony_ci#define ASSERT_MEM_HEX_NE(a, b, size) \ 233e66f31c5Sopenharmony_ci ASSERT_BASE_HEX(memcmp(a, b, size) != 0, a, !=, b, size) 234e66f31c5Sopenharmony_ci 235e66f31c5Sopenharmony_ci#define ASSERT_NULL(a) \ 236e66f31c5Sopenharmony_ci ASSERT_BASE(a, ==, NULL, void*, "p") 237e66f31c5Sopenharmony_ci 238e66f31c5Sopenharmony_ci#define ASSERT_NOT_NULL(a) \ 239e66f31c5Sopenharmony_ci ASSERT_BASE(a, !=, NULL, void*, "p") 240e66f31c5Sopenharmony_ci 241e66f31c5Sopenharmony_ci#define ASSERT_PTR_EQ(a, b) \ 242e66f31c5Sopenharmony_ci ASSERT_BASE(a, ==, b, void*, "p") 243e66f31c5Sopenharmony_ci 244e66f31c5Sopenharmony_ci#define ASSERT_PTR_NE(a, b) \ 245e66f31c5Sopenharmony_ci ASSERT_BASE(a, !=, b, void*, "p") 246e66f31c5Sopenharmony_ci 247e66f31c5Sopenharmony_ci#define ASSERT_PTR_LT(a, b) \ 248e66f31c5Sopenharmony_ci ASSERT_BASE(a, <, b, void*, "p") 249e66f31c5Sopenharmony_ci 250e66f31c5Sopenharmony_ci/* This macro cleans up the event loop. This is used to avoid valgrind 251e66f31c5Sopenharmony_ci * warnings about memory being "leaked" by the event loop. 252e66f31c5Sopenharmony_ci */ 253e66f31c5Sopenharmony_ci#define MAKE_VALGRIND_HAPPY(loop) \ 254e66f31c5Sopenharmony_ci do { \ 255e66f31c5Sopenharmony_ci close_loop(loop); \ 256e66f31c5Sopenharmony_ci ASSERT_EQ(0, uv_loop_close(loop)); \ 257e66f31c5Sopenharmony_ci uv_library_shutdown(); \ 258e66f31c5Sopenharmony_ci } while (0) 259e66f31c5Sopenharmony_ci 260e66f31c5Sopenharmony_ci/* Just sugar for wrapping the main() for a task or helper. */ 261e66f31c5Sopenharmony_ci#define TEST_IMPL(name) \ 262e66f31c5Sopenharmony_ci int run_test_##name(void); \ 263e66f31c5Sopenharmony_ci int run_test_##name(void) 264e66f31c5Sopenharmony_ci 265e66f31c5Sopenharmony_ci#define BENCHMARK_IMPL(name) \ 266e66f31c5Sopenharmony_ci int run_benchmark_##name(void); \ 267e66f31c5Sopenharmony_ci int run_benchmark_##name(void) 268e66f31c5Sopenharmony_ci 269e66f31c5Sopenharmony_ci#define HELPER_IMPL(name) \ 270e66f31c5Sopenharmony_ci int run_helper_##name(void); \ 271e66f31c5Sopenharmony_ci int run_helper_##name(void) 272e66f31c5Sopenharmony_ci 273e66f31c5Sopenharmony_ci/* Format big numbers nicely. */ 274e66f31c5Sopenharmony_cichar* fmt(char (*buf)[32], double d); 275e66f31c5Sopenharmony_ci 276e66f31c5Sopenharmony_ci/* Reserved test exit codes. */ 277e66f31c5Sopenharmony_cienum test_status { 278e66f31c5Sopenharmony_ci TEST_OK = 0, 279e66f31c5Sopenharmony_ci TEST_SKIP = 7 280e66f31c5Sopenharmony_ci}; 281e66f31c5Sopenharmony_ci 282e66f31c5Sopenharmony_ci#define RETURN_OK() \ 283e66f31c5Sopenharmony_ci do { \ 284e66f31c5Sopenharmony_ci return TEST_OK; \ 285e66f31c5Sopenharmony_ci } while (0) 286e66f31c5Sopenharmony_ci 287e66f31c5Sopenharmony_ci#define RETURN_SKIP(explanation) \ 288e66f31c5Sopenharmony_ci do { \ 289e66f31c5Sopenharmony_ci fprintf(stderr, "%s\n", explanation); \ 290e66f31c5Sopenharmony_ci fflush(stderr); \ 291e66f31c5Sopenharmony_ci return TEST_SKIP; \ 292e66f31c5Sopenharmony_ci } while (0) 293e66f31c5Sopenharmony_ci 294e66f31c5Sopenharmony_ci#if !defined(_WIN32) 295e66f31c5Sopenharmony_ci 296e66f31c5Sopenharmony_ci# define TEST_FILE_LIMIT(num) \ 297e66f31c5Sopenharmony_ci do { \ 298e66f31c5Sopenharmony_ci struct rlimit lim; \ 299e66f31c5Sopenharmony_ci lim.rlim_cur = (num); \ 300e66f31c5Sopenharmony_ci lim.rlim_max = lim.rlim_cur; \ 301e66f31c5Sopenharmony_ci if (setrlimit(RLIMIT_NOFILE, &lim)) \ 302e66f31c5Sopenharmony_ci RETURN_SKIP("File descriptor limit too low."); \ 303e66f31c5Sopenharmony_ci } while (0) 304e66f31c5Sopenharmony_ci 305e66f31c5Sopenharmony_ci#else /* defined(_WIN32) */ 306e66f31c5Sopenharmony_ci 307e66f31c5Sopenharmony_ci# define TEST_FILE_LIMIT(num) do {} while (0) 308e66f31c5Sopenharmony_ci 309e66f31c5Sopenharmony_ci#endif 310e66f31c5Sopenharmony_ci 311e66f31c5Sopenharmony_ci#if !defined(snprintf) && defined(_MSC_VER) && _MSC_VER < 1900 312e66f31c5Sopenharmony_ciextern int snprintf(char*, size_t, const char*, ...); 313e66f31c5Sopenharmony_ci#endif 314e66f31c5Sopenharmony_ci 315e66f31c5Sopenharmony_ci#if defined(__clang__) || \ 316e66f31c5Sopenharmony_ci defined(__GNUC__) || \ 317e66f31c5Sopenharmony_ci defined(__INTEL_COMPILER) 318e66f31c5Sopenharmony_ci# define UNUSED __attribute__((unused)) 319e66f31c5Sopenharmony_ci#else 320e66f31c5Sopenharmony_ci# define UNUSED 321e66f31c5Sopenharmony_ci#endif 322e66f31c5Sopenharmony_ci 323e66f31c5Sopenharmony_ci#if defined(_WIN32) 324e66f31c5Sopenharmony_ci#define notify_parent_process() ((void) 0) 325e66f31c5Sopenharmony_ci#else 326e66f31c5Sopenharmony_ciextern void notify_parent_process(void); 327e66f31c5Sopenharmony_ci#endif 328e66f31c5Sopenharmony_ci 329e66f31c5Sopenharmony_ci/* Fully close a loop */ 330e66f31c5Sopenharmony_cistatic void close_walk_cb(uv_handle_t* handle, void* arg) { 331e66f31c5Sopenharmony_ci if (!uv_is_closing(handle)) 332e66f31c5Sopenharmony_ci uv_close(handle, NULL); 333e66f31c5Sopenharmony_ci} 334e66f31c5Sopenharmony_ci 335e66f31c5Sopenharmony_ciUNUSED static void close_loop(uv_loop_t* loop) { 336e66f31c5Sopenharmony_ci uv_walk(loop, close_walk_cb, NULL); 337e66f31c5Sopenharmony_ci uv_run(loop, UV_RUN_DEFAULT); 338e66f31c5Sopenharmony_ci} 339e66f31c5Sopenharmony_ci 340e66f31c5Sopenharmony_ciUNUSED static int can_ipv6(void) { 341e66f31c5Sopenharmony_ci uv_interface_address_t* addr; 342e66f31c5Sopenharmony_ci int supported; 343e66f31c5Sopenharmony_ci int count; 344e66f31c5Sopenharmony_ci int i; 345e66f31c5Sopenharmony_ci 346e66f31c5Sopenharmony_ci if (uv_interface_addresses(&addr, &count)) 347e66f31c5Sopenharmony_ci return 0; /* Assume no IPv6 support on failure. */ 348e66f31c5Sopenharmony_ci 349e66f31c5Sopenharmony_ci supported = 0; 350e66f31c5Sopenharmony_ci for (i = 0; supported == 0 && i < count; i += 1) 351e66f31c5Sopenharmony_ci supported = (AF_INET6 == addr[i].address.address6.sin6_family); 352e66f31c5Sopenharmony_ci 353e66f31c5Sopenharmony_ci uv_free_interface_addresses(addr, count); 354e66f31c5Sopenharmony_ci return supported; 355e66f31c5Sopenharmony_ci} 356e66f31c5Sopenharmony_ci 357e66f31c5Sopenharmony_ci#if defined(__CYGWIN__) || defined(__MSYS__) || defined(__PASE__) 358e66f31c5Sopenharmony_ci# define NO_FS_EVENTS "Filesystem watching not supported on this platform." 359e66f31c5Sopenharmony_ci#endif 360e66f31c5Sopenharmony_ci 361e66f31c5Sopenharmony_ci#if defined(__MSYS__) 362e66f31c5Sopenharmony_ci# define NO_SEND_HANDLE_ON_PIPE \ 363e66f31c5Sopenharmony_ci "MSYS2 runtime does not support sending handles on pipes." 364e66f31c5Sopenharmony_ci#elif defined(__CYGWIN__) 365e66f31c5Sopenharmony_ci# define NO_SEND_HANDLE_ON_PIPE \ 366e66f31c5Sopenharmony_ci "Cygwin runtime does not support sending handles on pipes." 367e66f31c5Sopenharmony_ci#endif 368e66f31c5Sopenharmony_ci 369e66f31c5Sopenharmony_ci#if defined(__MSYS__) 370e66f31c5Sopenharmony_ci# define NO_SELF_CONNECT \ 371e66f31c5Sopenharmony_ci "MSYS2 runtime hangs on listen+connect in same process." 372e66f31c5Sopenharmony_ci#elif defined(__CYGWIN__) 373e66f31c5Sopenharmony_ci# define NO_SELF_CONNECT \ 374e66f31c5Sopenharmony_ci "Cygwin runtime hangs on listen+connect in same process." 375e66f31c5Sopenharmony_ci#endif 376e66f31c5Sopenharmony_ci 377e66f31c5Sopenharmony_ci#if !defined(__linux__) && \ 378e66f31c5Sopenharmony_ci !(defined(__FreeBSD__) && __FreeBSD_version >= 1301000) && \ 379e66f31c5Sopenharmony_ci !defined(_WIN32) 380e66f31c5Sopenharmony_ci# define NO_CPU_AFFINITY \ 381e66f31c5Sopenharmony_ci "affinity not supported on this platform." 382e66f31c5Sopenharmony_ci#endif 383e66f31c5Sopenharmony_ci 384e66f31c5Sopenharmony_ci#endif /* TASK_H_ */ 385