// 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 https://mozilla.org/MPL/2.0/. #pragma once #include #include #include "scoped.h" static inline void _tlsl_close_if_nonnegative(int *fd) { if (*fd >= 0) close(*fd); } DEF_SCOPED_TYPE(fd, int, -1, _tlsl_close_if_nonnegative) #define FD_SCOPED(VAL) SCOPED(fd, int, VAL) #define FD_CLOSE(FD) _tlsl_scoped_fd_cleanup(FD) #define FD_RELEASE(FD) _tlsl_scoped_fd_release(FD) static inline int setsockopt_int(int fd, int level, int option, int val) { return setsockopt(fd, level, option, &val, sizeof(val)); }