-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnection.h
More file actions
67 lines (52 loc) · 1.22 KB
/
Copy pathconnection.h
File metadata and controls
67 lines (52 loc) · 1.22 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
#ifndef __CONNECTION_H__
#define __CONNECTION_H__
#include <string>
#include <cstring>
#include <sstream>
struct sockaddr_in;
class ConnectionException {
public:
ConnectionException(std::string reason, int _errno)
{
init(reason, _errno);
}
ConnectionException(std::string reason)
{
init(reason, errno);
}
ConnectionException() {
reason = strerror(errno);
}
std::string reason;
private:
void init(std::string reason, int _errno)
{
std::stringstream ss;
ss << reason << ": " << strerror(_errno);
this->reason = ss.str();
}
};
class Connection {
public:
Connection(int client_connection, sockaddr_in client_info);
~Connection();
int readInt4();
void writeInt4(const int data);
float readFloat4();
void writeFloat4(const float data);
void flush();
void close();
private:
/**
* Assuming void* data is point to 4 bytes of valid data
*/
void writeData4(const void *data);
/**
* Assuming void* data is point to 4 bytes of valid data
*/
void readData4(void *data);
std::string address;
int port;
int socketfd;
};
#endif /* __CONNECTION_H__ */