-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.hh
More file actions
71 lines (56 loc) · 1.15 KB
/
client.hh
File metadata and controls
71 lines (56 loc) · 1.15 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef __MAKEMORE_CLIENT_HH__
#define __MAKEMORE_CLIENT_HH__ 1
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <vector>
#include <map>
#include <set>
#include <string>
namespace makemore {
struct Client {
int s;
uint32_t ip;
uint8_t *outbuf;
unsigned int outbufk, outbufn;
uint8_t *inpbuf;
unsigned int inpbufk, inpbufn;
Client(int _s, uint32_t _ip) {
s = _s;
ip = _ip;
outbufn = (10 << 20);
outbufk = 0;
outbuf = new uint8_t[outbufn];
inpbufn = (10 << 20);
inpbufk = 0;
inpbuf = new uint8_t[inpbufn];
}
~Client() {
delete[] inpbuf;
delete[] outbuf;
::close(s);
}
bool need_flush() {
return (outbufk > 0);
}
bool need_slurp() {
return (inpbufk < inpbufn);
}
bool write(const uint8_t *buf, unsigned int len);
bool can_write(unsigned int len) {
return (outbufk + len <= outbufn);
}
bool read(uint8_t *buf, unsigned int len);
bool can_read(unsigned int len) {
return (inpbufk >= len);
}
bool slurp();
bool flush();
};
}
#endif