forked from DeckerSU/yiimp-stratum-equihash
-
Notifications
You must be signed in to change notification settings - Fork 3
/
socket.h
59 lines (48 loc) · 1.14 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
58
59
#define YAAMP_SOCKET_BUFSIZE (4*1024)
struct YAAMP_SOCKET
{
char ip[64];
int port;
// pthread_mutex_t mutex;
int sock;
int buflen;
char buffer[YAAMP_SOCKET_BUFSIZE];
int last_read;
int total_read;
};
bool socket_connected(YAAMP_SOCKET *s);
void socket_real_ip(YAAMP_SOCKET *s);
YAAMP_SOCKET *socket_initialize(int sock);
void socket_close(YAAMP_SOCKET *s);
json_value *socket_nextjson(YAAMP_SOCKET *s, YAAMP_CLIENT *client=NULL);
int socket_send(YAAMP_SOCKET *s, const char *format, ...);
int socket_send_raw(YAAMP_SOCKET *s, const char *buffer, int size);
static union {
struct {
char line[108];
} v1;
struct {
uint8_t sig[12];
uint8_t ver_cmd;
uint8_t fam;
uint16_t len;
union {
struct { /* for TCP/UDP over IPv4, len = 12 */
uint32_t src_addr;
uint32_t dst_addr;
uint16_t src_port;
uint16_t dst_port;
} ip4;
struct { /* for TCP/UDP over IPv6, len = 36 */
uint8_t src_addr[16];
uint8_t dst_addr[16];
uint16_t src_port;
uint16_t dst_port;
} ip6;
struct { /* for AF_UNIX sockets, len = 216 */
uint8_t src_addr[108];
uint8_t dst_addr[108];
} unx;
} addr;
} v2;
} hdr;