#include "llvm/Support/raw_socket_stream.h"
#include "llvm/Config/config.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
#include <atomic>
#include <fcntl.h>
#include <functional>
#include <thread>
#ifndef _WIN32
#include <poll.h>
#include <sys/socket.h>
#include <sys/un.h>
#else
#include "llvm/Support/Windows/WindowsSupport.h"
#include <winsock2.h>
#include <afunix.h>
#include <io.h>
#endif
#if defined(HAVE_UNISTD_H)
#include <unistd.h>
#endif
usingnamespacellvm;
#ifdef _WIN32
WSABalancer::WSABalancer() {
WSADATA WsaData;
::memset(&WsaData, 0, sizeof(WsaData));
if (WSAStartup(MAKEWORD(2, 2), &WsaData) != 0) {
llvm::report_fatal_error("WSAStartup failed");
}
}
WSABalancer::~WSABalancer() { WSACleanup(); }
#endif
static std::error_code getLastSocketErrorCode() { … }
static sockaddr_un setSocketAddr(StringRef SocketPath) { … }
static Expected<int> getSocketFD(StringRef SocketPath) { … }
ListeningSocket::ListeningSocket(int SocketFD, StringRef SocketPath,
int PipeFD[2])
: … { … }
ListeningSocket::ListeningSocket(ListeningSocket &&LS)
: … { … }
Expected<ListeningSocket> ListeningSocket::createUnix(StringRef SocketPath,
int MaxBacklog) { … }
static std::error_code
manageTimeout(const std::chrono::milliseconds &Timeout,
const std::function<int()> &getActiveFD,
const std::optional<int> &CancelFD = std::nullopt) { … }
Expected<std::unique_ptr<raw_socket_stream>>
ListeningSocket::accept(const std::chrono::milliseconds &Timeout) { … }
void ListeningSocket::shutdown() { … }
ListeningSocket::~ListeningSocket() { … }
raw_socket_stream::raw_socket_stream(int SocketFD)
: … { … }
raw_socket_stream::~raw_socket_stream() { … }
Expected<std::unique_ptr<raw_socket_stream>>
raw_socket_stream::createConnectedUnix(StringRef SocketPath) { … }
ssize_t raw_socket_stream::read(char *Ptr, size_t Size,
const std::chrono::milliseconds &Timeout) { … }