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.

22 lines
490 B
C

#pragma once
#include <unistd.h>
#include <sys/socket.h>
#include "scoped.h"
static inline void _close_if_nonnegative(int fd) {
if (fd >= 0)
close(fd);
}
DEF_SCOPED_TYPE(fd, int, -1, _close_if_nonnegative)
#define FD_SCOPED(VAL) SCOPED(fd, int, VAL)
#define FD_CLOSE(FD) _scoped_fd_cleanup(FD)
#define FD_RELEASE(FD) _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));
}