forked from embeddedmz/socket-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTCPServer.h
More file actions
62 lines (47 loc) · 1.78 KB
/
TCPServer.h
File metadata and controls
62 lines (47 loc) · 1.78 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
/*
* @file TCPServer.h
* @brief wrapper for TCP server
*
* @author Mohamed Amine Mzoughi <[email protected]>
* @date 2013-05-11
*/
#ifndef INCLUDE_TCPSERVER_H_
#define INCLUDE_TCPSERVER_H_
#include <string>
#include <vector>
#include "Socket.h"
class CTCPSSLServer;
class CTCPServer : public ASocket
{
friend class CTCPSSLServer;
public:
explicit CTCPServer(const LogFnCallback oLogger,
/*const std::string& strAddr,*/ const std::string& strPort,
const SettingsFlag eSettings = ALL_FLAGS) /*throw (EResolveError)*/;
~CTCPServer() override;
// copy constructor and assignment operator are disabled
CTCPServer(const CTCPServer&) = delete;
CTCPServer& operator=(const CTCPServer&) = delete;
/* returns the socket of the accepted client, the waiting period can be set */
int Listen(Socket& ClientSocket, size_t msec = ACCEPT_WAIT_INF_DELAY);
void Disconnect(Socket& ClientSocket) const;
int Receive(Socket ClientSocket, char* pData, size_t uSize, bool bReadFully = true) const;
int Send(Socket ClientSocket, const char* pData, size_t uSize) const;
int Send(Socket ClientSocket, const std::string& strData) const;
int Send(Socket ClientSocket, const std::vector<char>& Data) const;
bool SetRcvTimeout(Socket ClientSocket, unsigned int msec_timeout);
bool SetSndTimeout(Socket ClientSocket, unsigned int msec_timeout);
#ifndef _WIN32
bool SetRcvTimeout(Socket ClientSocket, struct timeval timeout);
bool SetSndTimeout(Socket ClientSocket, struct timeval timeout);
#endif
private:
bool InitAddrInfo();
protected:
Socket m_ListenSocket;
//std::string m_strHost;
std::string m_strPort;
struct addrinfo* m_pResultAddrInfo;
struct addrinfo m_HintsAddrInfo;
};
#endif