13#if defined(_MSC_VER) && (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
26#if defined(_WIN32) && defined(AF_UNIX) || defined(__unix__) || defined(__APPLE__)
95 explicit UnixSocket(std::string_view path, std::size_t bufferSize = 512);
141 void listen(
int backlog = SOMAXCONN) const;
162 [[nodiscard]]
size_t write(std::string_view data) const;
171 size_t read(
char* buffer, std::
size_t len) const;
181 static_assert(std::is_trivially_copyable_v<T>,
"UnixSocket::read<T>() only supports trivially copyable types");
183 const int len = ::recv(
getSocketFd(),
reinterpret_cast<char*
>(&value),
185 static_cast<int>(
sizeof(T)),
Exception class for socket-related errors in jsocketpp.
Defines the SocketOptions base class for cross-platform socket option access.
Represents socket-related errors in the jsocketpp library.
Definition SocketException.hpp:63
SOCKADDR_UN _addr
Address structure for Unix domain sockets.
Definition UnixSocket.hpp:255
static bool isPathInUse(std::string_view path)
Checks whether a UNIX domain socket path is currently in use (i.e., a process is listening on it).
Definition UnixSocket.cpp:232
UnixSocket & operator=(const UnixSocket &)=delete
Copy assignment operator deleted to prevent copying.
void bind()
Binds the socket.
Definition UnixSocket.cpp:79
std::string _socketPath
Path for the Unix domain socket.
Definition UnixSocket.hpp:254
void close()
Closes the socket.
Definition UnixSocket.cpp:119
UnixSocket(std::string_view path, std::size_t bufferSize=512)
Constructs a UnixSocket and connects or binds to the specified path.
Definition UnixSocket.cpp:8
UnixSocket()
Default constructor for internal use (e.g., accept()).
Definition UnixSocket.hpp:250
void setTimeout(int millis) const
Sets a timeout for socket operations.
Definition UnixSocket.cpp:209
T read()
Reads a trivially copyable type from the socket.
Definition UnixSocket.hpp:179
void connect()
Connects the socket.
Definition UnixSocket.cpp:109
bool _isListening
True if the socket is listening for connections.
Definition UnixSocket.hpp:253
std::string getSocketPath() const
Returns the path of the Unix domain socket.
Definition UnixSocket.hpp:215
size_t read(char *buffer, std::size_t len) const
Reads data from the socket into a buffer.
Definition UnixSocket.cpp:163
void listen(int backlog=SOMAXCONN) const
Marks the socket as a passive socket to accept incoming connections.
Definition UnixSocket.cpp:99
std::vector< char > _internalBuffer
Internal buffer for read operations.
Definition UnixSocket.hpp:256
void setNonBlocking(bool nonBlocking) const
Sets the socket to non-blocking or blocking mode.
Definition UnixSocket.cpp:181
size_t write(std::string_view data) const
Writes data to the socket.
Definition UnixSocket.cpp:145
~UnixSocket() noexcept override
Destructor.
Definition UnixSocket.cpp:28
bool isValid() const
Checks if the socket is valid (open).
Definition UnixSocket.hpp:209
UnixSocket accept() const
Accepts an incoming connection.
Definition UnixSocket.cpp:128
UnixSocket(const UnixSocket &)=delete
Copy constructor deleted to prevent copying.
Common platform and utility includes for jsocketpp.
SocketOptions()=delete
Default constructor (deleted) for SocketOptions base class.
SOCKET getSocketFd() const noexcept
Retrieves the native socket handle (file descriptor or OS-level handle).
Definition SocketOptions.hpp:275
A C++ socket library providing Java-style networking interfaces.
Definition BufferView.hpp:16
std::string SocketErrorMessage(int error, bool gaiStrerror=false)
Convert a socket-related error code to a human-readable message.
Definition common.cpp:5
constexpr SOCKET INVALID_SOCKET
Definition common.hpp:264
sockaddr_un SOCKADDR_UN
Definition common.hpp:266
int GetSocketError()
Definition common.hpp:246
constexpr SOCKET SOCKET_ERROR
Definition common.hpp:265