-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsock_stream.cpp
More file actions
46 lines (35 loc) · 859 Bytes
/
Copy pathsock_stream.cpp
File metadata and controls
46 lines (35 loc) · 859 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
#include "sock_stream.hpp"
#include "exception.hpp"
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
SockStream::~SockStream()
{
::close(socket_);
}
SockStream::SockStream() : socket_(0)
{
// if((socket_ = socket(AF_INET, SOCK_STREAM, 0)) == -1)
// {
// throw exception("Can't create socket");
// }
//
// int yes;
//
// if(setsockopt(socket_, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1)
// {
// throw exception("Can't set socket options");
// }
}
int SockStream::recv(void* buf, size_t len, unsigned int timeout)
{
struct timeval tv;
tv.tv_sec = timeout;
tv.tv_usec = 0;
::setsockopt(socket_, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv,sizeof(struct timeval));
return ::recv(socket_, buf, len, 0);
}
int SockStream::send(const void* buf, size_t len)
{
return ::send(socket_, buf, len, 0);
}