testing: fix osx
[awesomized/libmemcached] / test / lib / Connection.hpp
1 #pragma once
2
3 #include "common.hpp"
4
5 #include <sys/socket.h>
6 #include <sys/un.h>
7
8 class Connection {
9 public:
10 explicit Connection(socket_or_port_t socket_or_port);
11 ~Connection();
12
13 friend void swap(Connection &a, Connection &b);
14 void swap(Connection &conn);
15
16 Connection(const Connection &conn);
17 Connection &operator = (const Connection &conn);
18
19 Connection(Connection &&conn) noexcept ;
20 Connection &operator = (Connection &&conn) noexcept ;
21
22 int getError();
23 int getLastError();
24
25 bool isWritable();
26 bool isOpen();
27
28 bool open();
29 void close();
30
31 private:
32 int sock{-1}, last_err{-1};
33 sockaddr_storage addr{};
34 enum sockaddr_size {
35 NONE = 0,
36 UNIX = sizeof(sockaddr_un),
37 INET = sizeof(sockaddr_in),
38 INET6 = sizeof(sockaddr_in6)
39 } size;
40 bool connected{false};
41
42 static string error(const initializer_list<string> &args);
43 };