LLVM 20.0.0git
|
Manages a passive (i.e., listening) UNIX domain socket. More...
#include "llvm/Support/raw_socket_stream.h"
Public Member Functions | |
~ListeningSocket () | |
ListeningSocket (ListeningSocket &&LS) | |
ListeningSocket (const ListeningSocket &LS)=delete | |
ListeningSocket & | operator= (const ListeningSocket &)=delete |
void | shutdown () |
Closes the FD, unlinks the socket file, and writes to PipeFD. | |
Expected< std::unique_ptr< raw_socket_stream > > | accept (const std::chrono::milliseconds &Timeout=std::chrono::milliseconds(-1)) |
Accepts an incoming connection on the listening socket. | |
Static Public Member Functions | |
static Expected< ListeningSocket > | createUnix (StringRef SocketPath, int MaxBacklog=llvm::hardware_concurrency().compute_thread_count()) |
Creates a listening socket bound to the specified file system path. | |
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 raw_socket_streams
that function as client connections.
Usage example:
Definition at line 59 of file raw_socket_stream.h.
ListeningSocket::~ListeningSocket | ( | ) |
Definition at line 297 of file raw_socket_stream.cpp.
References shutdown().
ListeningSocket::ListeningSocket | ( | ListeningSocket && | LS | ) |
Definition at line 101 of file raw_socket_stream.cpp.
|
delete |
Expected< std::unique_ptr< raw_socket_stream > > ListeningSocket::accept | ( | const std::chrono::milliseconds & | Timeout = std::chrono::milliseconds(-1) | ) |
Accepts an incoming connection on the listening socket.
This method can optionally either block until a connection is available or timeout after a specified amount of time has passed. By default the method will block until the socket has recieved a connection. If the accept timesout this method will return std::errc:timed_out
Timeout | An optional timeout duration in milliseconds. Setting Timeout to a negative number causes accept to block indefinitely |
Definition at line 255 of file raw_socket_stream.cpp.
References accept(), getLastSocketErrorCode(), and manageTimeout().
Referenced by accept().
|
static |
Creates a listening socket bound to the specified file system path.
Handles the socket creation, binding, and immediately starts listening for incoming connections.
SocketPath | The file system path where the socket will be created |
MaxBacklog | The max number of connections in a socket's backlog |
Definition at line 111 of file raw_socket_stream.cpp.
References _, Addr, llvm::consumeError(), llvm::sys::fs::exists(), getLastSocketErrorCode(), getSocketFD(), setSocketAddr(), and llvm::Expected< T >::takeError().
|
delete |
void ListeningSocket::shutdown | ( | ) |
Closes the FD, unlinks the socket file, and writes to PipeFD.
After the construction of the ListeningSocket, shutdown is signal safe if it is called during the lifetime of the object. shutdown can be called concurrently with ListeningSocket::accept as writing to PipeFD will cause a blocking call to ::poll to return.
Once shutdown is called there is no way to reinitialize ListeningSocket.
Definition at line 275 of file raw_socket_stream.cpp.
References llvm::write().
Referenced by ~ListeningSocket().