//===-- llvm/Support/raw_socket_stream.h - Socket streams --*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file contains raw_ostream implementations for streams to communicate // via UNIX sockets // //===----------------------------------------------------------------------===// #ifndef LLVM_SUPPORT_RAW_SOCKET_STREAM_H #define LLVM_SUPPORT_RAW_SOCKET_STREAM_H #include "llvm/Support/Threading.h" #include "llvm/Support/raw_ostream.h" #include <atomic> #include <chrono> namespace llvm { class raw_socket_stream; #ifdef _WIN32 /// Ensures proper initialization and cleanup of winsock resources /// /// Make sure that calls to WSAStartup and WSACleanup are balanced. class WSABalancer { public: WSABalancer(); ~WSABalancer(); }; #endif // _WIN32 /// Manages a passive (i.e., listening) UNIX domain socket /// /// The ListeningSocket class encapsulates a UNIX domain socket that can listen /// and accept incoming connections. ListeningSocket is portable and supports /// Windows builds begining with Insider Build 17063. ListeningSocket is /// designed for server-side operations, working alongside \p raw_socket_streams /// that function as client connections. /// /// Usage example: /// \code{.cpp} /// std::string Path = "/path/to/socket" /// Expected<ListeningSocket> S = ListeningSocket::createUnix(Path); /// /// if (S) { /// Expected<std::unique_ptr<raw_socket_stream>> connection = S->accept(); /// if (connection) { /// // Use the accepted raw_socket_stream for communication. /// } /// } /// \endcode /// class ListeningSocket { … }; //===----------------------------------------------------------------------===// // raw_socket_stream //===----------------------------------------------------------------------===// class raw_socket_stream : public raw_fd_stream { … }; } // end namespace llvm #endif