forked from fireice-uk/xmr-stak-cpu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
socket.h
57 lines (47 loc) · 1.06 KB
/
socket.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#pragma once
#include "socks.h"
class jpsock;
class base_socket
{
public:
virtual bool set_hostname(const char* sAddr) = 0;
virtual bool connect() = 0;
virtual int recv(char* buf, unsigned int len) = 0;
virtual bool send(const char* buf) = 0;
virtual void close(bool free) = 0;
};
class plain_socket : public base_socket
{
public:
plain_socket(jpsock* err_callback);
bool set_hostname(const char* sAddr);
bool connect();
int recv(char* buf, unsigned int len);
bool send(const char* buf);
void close(bool free);
private:
jpsock* pCallback;
addrinfo *pSockAddr;
addrinfo *pAddrRoot;
SOCKET hSocket;
};
typedef struct ssl_ctx_st SSL_CTX;
typedef struct bio_st BIO;
typedef struct ssl_st SSL;
class tls_socket : public base_socket
{
public:
tls_socket(jpsock* err_callback);
bool set_hostname(const char* sAddr);
bool connect();
int recv(char* buf, unsigned int len);
bool send(const char* buf);
void close(bool free);
private:
void init_ctx();
void print_error();
jpsock* pCallback;
SSL_CTX* ctx = nullptr;
BIO* bio = nullptr;
SSL* ssl = nullptr;
};