-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBaseClient.h
More file actions
89 lines (67 loc) · 1.55 KB
/
BaseClient.h
File metadata and controls
89 lines (67 loc) · 1.55 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef BASE_CLIENT_HPP_
#define BASE_CLIENT_HPP_
// CLient API v.0.0.02 alpha
// buffer, networking
#include "Errors.h"
#include <sys/time.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <cstdio>
class BaseClient {
/* static variables */
public:
/* internal structures */
struct server_t {
int ip;
int port;
};
struct buffer_t {
static const int DEFAULT_BUFFER = 64;
static const int MAXIMUM_BUFFER = 1024*1024*8;
char * data;
int allocated, size;
void push(const char * data, int length);
};
struct message_queue_t{
struct message_list{
char * message;
int length;
struct message_list *next, *prev;
} *lo, *hi;
int count;
bool isEmpty() const;
int getLength() const;
void push(const char * data, int length);
char * pop(); /* YOU HAVE TO FREE MEMORY MANUALLY */
message_queue_t();
~message_queue_t();
};
struct netinfo_t {
int descriptor;
};
private:
/* non-static data */
char message_separator;
server_t server;
buffer_t buffer;
netinfo_t netinfo;
protected:
message_queue_t message_queue;
private:
/* private methods */
int split_messages(char separator);
public:
/* public methods */
BaseClient (const char * ip, int port, char msp = '\0');
virtual ~BaseClient();
void send(const char * data, int length);
void send(const char * data);
int getDescriptor();
virtual int check(struct timeval timeout); /* check for incomming messages */
};
#endif