forked from lizhenghn123/CppLanguagePrograms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPassiveSocket.cpp
More file actions
46 lines (36 loc) · 879 Bytes
/
PassiveSocket.cpp
File metadata and controls
46 lines (36 loc) · 879 Bytes
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
#include "net/PassiveSocket.h"
NAMESPACE_ZL_NET_START
PassiveSocket::PassiveSocket(ZL_SOCKET fd) : Socket(fd)
{
}
PassiveSocket::PassiveSocket(const char *ip, int port) : Socket(SocketUtil::createSocket())
{
if(!Socket::bind(ip, port))
{
throw SocketException("Could not bind to port.");
}
if(!Socket::listen(5))
{
throw SocketException("Could not listen to port.");
}
}
PassiveSocket::~PassiveSocket()
{
}
const PassiveSocket& PassiveSocket::operator << (const std::string& data) const
{
if(!Socket::send(data))
{
throw SocketException("Could not write to socket.");
}
return *this;
}
const PassiveSocket& PassiveSocket::operator >> (std::string& data) const
{
if(!Socket::recv(data))
{
throw SocketException("Could not read from socket.");
}
return *this;
}
NAMESPACE_ZL_NET_END