aboutsummaryrefslogtreecommitdiff
path: root/include/DirectConnection.hpp
blob: c11871fe703ade6ecf355b50acea604e06601752 (plain)
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
#pragma once

#include <stdexcept>
#include "types.hpp"
#include "utils.hpp"

struct addrinfo;

namespace sibs
{
    class InvalidAddressException : public std::runtime_error
    {
    public:
        InvalidAddressException(const std::string &errMsg) : std::runtime_error(errMsg) {}
    };
    
    class ConnectionException : public std::runtime_error
    {
    public:
        ConnectionException(const std::string &errMsg) : std::runtime_error(errMsg) {}
    };
    
    class Ipv4
    {
        DISABLE_COPY(Ipv4)
    public:
        // Throws InvalidAddressException on error
        Ipv4(const char *ip, u16 port);
        ~Ipv4();
        
        struct addrinfo *address;
    };
    
    class DirectConnections
    {
        DISABLE_COPY(DirectConnections)
    public:
        DirectConnections();
        ~DirectConnections();
        
        void connect(const Ipv4 &address);
    private:
        void init();
        void cleanup();
    private:
        int eid;
        int mySocket;
    };
}