-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeneric_socket.cpp
More file actions
64 lines (47 loc) · 1.29 KB
/
generic_socket.cpp
File metadata and controls
64 lines (47 loc) · 1.29 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
#include "generic_socket.h"
#include <unistd.h>
#include <string>
#include <iostream>
GenericSocket::GenericSocket(bool verbose_in, bool debug_in) : host(""), service(""), socket_fd(-1), verbose(verbose_in), debug(debug_in)
{
if(debug)
std::cerr << "GenericSocket called" << std::endl;
}
GenericSocket::~GenericSocket()
{
if(debug)
std::cerr << "~GenericSocket called" << std::endl;
if(socket_fd >= 0)
::close(socket_fd);
}
void GenericSocket::connect(std::string_view host_in, std::string_view service_in, std::string_view key_in, int timeout)
{
if(debug)
std::cerr << "GenericSocket::connect called" << std::endl;
if(!host_in.empty())
host = host_in;
if(!service_in.empty())
service = service_in;
if(!key_in.empty())
key = key_in;
this->_connect(timeout);
}
void GenericSocket::disconnect()
{
if(debug)
std::cerr << "GenericSocket::disconnect called" << std::endl;
this->_disconnect();
}
void GenericSocket::send(const std::string &data, const int timeout) const
{
if(debug)
std::cerr << "GenericSocket::send called: " << data.length() << std::endl;
this->_send(data, timeout);
}
void GenericSocket::receive(std::string &data, const int timeout) const
{
if(debug)
std::cerr << "GenericSocket::receive called" << std::endl;
data.clear();
this->_receive(data, timeout);
}