13 #ifndef __STOUT_OS_POSIX_SOCKET_HPP__ 14 #define __STOUT_OS_POSIX_SOCKET_HPP__ 21 #include <sys/socket.h> 46 if ((s = ::
socket(family, type, protocol)) < 0) {
54 if (setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, &enable,
sizeof(
int)) == -1) {
67 return (error == EINTR);
76 return (error == EWOULDBLOCK || error == EAGAIN);
82 return (error == EINPROGRESS);
89 if (::fstat(fd, &statbuf) < 0) {
93 return S_ISSOCK(statbuf.st_mode) != 0;
99 std::array<int_fd, 2> result;
101 #if __APPLE__ || !defined(SOCK_CLOEXEC) 102 auto close = [](
const std::array<int_fd, 2>& fds) {
110 #if defined(SOCK_CLOEXEC) 111 type |= SOCK_CLOEXEC;
114 if (::
socketpair(family, type, 0, result.data()) != 0) {
118 #if !defined(SOCK_CLOEXEC) 124 return Error(
"Failed to cloexec socket: " + cloexec.
error());
128 if (cloexec.isError()) {
130 return Error(
"Failed to cloexec socket: " + cloexec.error());
143 sizeof(enable)) == -1) {
153 sizeof(enable)) == -1) {
164 #endif // __STOUT_OS_POSIX_SOCKET_HPP__ Try< int_fd > socket(int family, int type, int protocol)
Definition: socket.hpp:43
Definition: nothing.hpp:16
bool is_socket(int fd)
Definition: socket.hpp:86
Definition: errorbase.hpp:36
Try< Nothing > enable(const std::string &hierarchy, const std::string &cgroup)
bool is_inprogress_error(int error)
Definition: socket.hpp:80
bool S_ISSOCK(const int mode)
Definition: windows.hpp:230
Definition: errorbase.hpp:50
int bind(const int_fd &fd, const sockaddr *addr, socklen_t addrlen)
Definition: socket.hpp:143
Try< Nothing > cloexec(const InputFileDescriptors &stdinfds, const OutputFileDescriptors &stdoutfds, const OutputFileDescriptors &stderrfds)
Definition: subprocess.hpp:186
Try< std::array< int_fd, 2 > > socketpair(int family, int type, int protocol)
Definition: socket.hpp:97
int_fd accept(const int_fd &fd, sockaddr *addr, socklen_t *addrlen)
Definition: socket.hpp:132
bool is_restartable_error(int error)
Definition: socket.hpp:65
ssize_t send(const int_fd &fd, const void *buf, size_t len, int flags)
Definition: socket.hpp:159
Try< Nothing > cloexec(int fd)
Definition: fcntl.hpp:27
ssize_t recv(const int_fd &fd, void *buf, size_t len, int flags)
Definition: socket.hpp:168
Try< hashmap< std::string, uint64_t > > stat(const std::string &hierarchy, const std::string &cgroup, const std::string &file)
static Try error(const E &e)
Definition: try.hpp:43
bool isError() const
Definition: try.hpp:78
std::string error(const std::string &msg, uint32_t code)
Try< uint32_t > type(const std::string &path)
int connect(const int_fd &fd, const sockaddr *address, socklen_t addrlen)
Definition: socket.hpp:151
int int_fd
Definition: int_fd.hpp:35
bool is_retryable_error(int error)
Definition: socket.hpp:74