41 lines
911 B
C++
41 lines
911 B
C++
#pragma once
|
|
#include <string>
|
|
#include <tuple>
|
|
#include <vector>
|
|
|
|
namespace SimpleSock
|
|
{
|
|
class sock
|
|
{
|
|
public:
|
|
sock();
|
|
sock(sock&&) noexcept;
|
|
~sock();
|
|
sock(const sock&) = delete;
|
|
sock& operator = (const sock&) = delete;
|
|
int connect(const std::string& ip, int port);
|
|
int bind(const std::string& ip, int port);
|
|
int listen(int backlog = 0);
|
|
sock accept();
|
|
int send(const void* buffer, size_t length);
|
|
int sendall(const void* buffer, size_t length);
|
|
int recv(void* buffer, size_t length);
|
|
void close();
|
|
|
|
bool valid();
|
|
int getError();
|
|
std::string getErrorMessage();
|
|
private:
|
|
int create_socket();
|
|
|
|
int fd;
|
|
int _code;
|
|
std::string _msg;
|
|
};
|
|
|
|
std::tuple<std::vector<std::string>, int, std::string> DNSResolve(const std::string& host);
|
|
int ConnectWithHttpProxy(sock& s, const std::string& proxyIP, int proxyPort, const std::string& host, int port);
|
|
|
|
int InitSimpleSock();
|
|
}
|