1
0
mirror of synced 2024-12-15 17:21:16 +01:00
ImHex/lib/libimhex/include/hex/helpers/socket.hpp

55 lines
1.1 KiB
C++
Raw Normal View History

#pragma once
#include <hex.hpp>
#include <string>
#include <vector>
#if defined(OS_WINDOWS)
#include <winsock2.h>
2021-12-07 23:09:30 +01:00
#include <ws2tcpip.h>
#include <windows.h>
2021-12-07 23:09:30 +01:00
#define SOCKET_NONE INVALID_SOCKET
#else
#include <unistd.h>
2021-12-07 23:09:30 +01:00
#include <sys/socket.h>
#include <netinet/ip.h>
#include <arpa/inet.h>
#define SOCKET_NONE -1
#endif
namespace hex {
class Socket {
public:
Socket() = default;
Socket(const Socket&) = delete;
Socket(Socket &&other);
Socket(const std::string &address, u16 port);
~Socket();
void connect(const std::string &address, u16 port);
void disconnect();
[[nodiscard]]
bool isConnected() const;
std::string readString(size_t size = 0x1000) const;
std::vector<u8> readBytes(size_t size = 0x1000) const;
void writeString(const std::string &string) const;
void writeBytes(const std::vector<u8> &bytes) const;
private:
bool m_connected = false;
#if defined(OS_WINDOWS)
2021-12-07 23:09:30 +01:00
SOCKET m_socket = SOCKET_NONE;
#else
2021-12-07 23:09:30 +01:00
int m_socket = SOCKET_NONE;
#endif
};
}