You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
717 B
C

// 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 <unistd.h>
#include <sys/socket.h>
#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));
}