forked from augcampos/asterisk-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTCPSocket.h
More file actions
73 lines (57 loc) · 1.52 KB
/
TCPSocket.h
File metadata and controls
73 lines (57 loc) · 1.52 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
/*
* TCPSocket.h
*
* Created on: 29 de Jun de 2011
* Author: augcampos
*/
#ifndef TCPSOCKET_H_
#define TCPSOCKET_H_
#include <errno.h>
#include <string.h>
#ifdef _WIN32
#include <io.h>
#include <fcntl.h>
#include <winsock2.h>
#else
#include <netdb.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#endif
#include <boost/thread/mutex.hpp>
#include "IPAddress.h"
#define NO_TIMEOUT 0
namespace asteriskcpp {
class TCPSocket {
protected:
int socketFD;
bool releaseForced;
IPAddress ipAddress;
boost::mutex mutRead;
boost::mutex mutWrite;
IPAddress peerAddress;
struct timeval timeout;
public:
TCPSocket();
TCPSocket(const int socketFD);
TCPSocket(const IPAddress& ipAddress);
virtual ~TCPSocket();
int readData(char* buf, const unsigned int size);
std::string readData();
void writeData(const char* buf, const unsigned int size);
void writeData(const std::string& data);
void setTimeout(const unsigned long timeout);
unsigned long getTimeout();
void release();
void close();
bool check4readData(const unsigned long timeout);
IPAddress getLocalAddress();
IPAddress getPeerAddress();
int getSocketFD();
private:
void resolvePeerAddr();
void resolveLocalAddr();
};
}
#endif /* TCPSOCKET_H_ */