discord_ipc_cpp 1.0.0
C++ library for interfacing with Discord IPC socket.
Loading...
Searching...
No Matches
socket_client.hpp
1/*
2 Copyright 2025 Peter Duanmu
3
4 You should have received a copy of the GNU General Public License along
5 with discord_ipc_cpp. If not, see <https://www.gnu.org/licenses/>.
6*/
7
8#ifndef DISCORD_IPC_CPP_INCLUDE_DISCORD_IPC_CPP_SOCKET_CLIENT_HPP_
9#define DISCORD_IPC_CPP_INCLUDE_DISCORD_IPC_CPP_SOCKET_CLIENT_HPP_
10
11#include <poll.h>
12#include <sys/socket.h>
13#include <sys/un.h>
14
15#include <string>
16#include <optional>
17#include <vector>
18
36 private:
40 std::string _socket_file;
41
45 int _client_socket;
49 struct sockaddr_un _server_addr;
50
54 struct pollfd _fds[1];
55
56 public:
60 explicit SocketClient(const std::string& socket_file);
67
73 bool connect();
79 bool close();
80
90 bool send_data(const std::vector<char>& data);
104 std::optional<std::vector<char>> recv_data(int buffer_size);
119 std::optional<std::vector<char>> recv_data(int buffer_size, int timeout);
120};
121} // namespace discord_ipc_cpp::websockets
122
123#endif // DISCORD_IPC_CPP_INCLUDE_DISCORD_IPC_CPP_SOCKET_CLIENT_HPP_
bool connect()
Attempts to connect to the socket file.
~SocketClient()
Cleans up socket the socket connection.
SocketClient(const std::string &socket_file)
Creates socket connection precursor information.
std::optional< std::vector< char > > recv_data(int buffer_size, int timeout)
Receive data from socket on timeout.
bool send_data(const std::vector< char > &data)
Sends data to socket.
std::optional< std::vector< char > > recv_data(int buffer_size)
Receive data from socket.
bool close()
Attempts to close connection to socket file.
Underlying websocket communications.