tls.hpp

1
2
3
4
5
6
7
#pragma once


#include <felspar/io/warden.hpp>


namespace felspar::io {

TLS secured TCP connection

11
12
13
14
15
16
17
18
19
20
21
22
23
24
    class tls final {
        struct impl;
        std::unique_ptr<impl> p;

        explicit tls(std::unique_ptr<impl>);

      public:
        tls();
        tls(tls const &) = delete;
        tls(tls &&);
        ~tls();

        tls &operator=(tls const &) = delete;
        tls &operator=(tls &&);

Connect to a TLS secured server over TCP

27
28
29
30
31
32
33
34
        static warden::task<tls>
                connect(warden &,
                        char const *snI_hostname,
                        sockaddr const *addr,
                        socklen_t addrlen,
                        std::optional<std::chrono::nanoseconds> timeout = {},
                        felspar::source_location const & =
                                felspar::source_location::current());

Read from the connection

37
38
39
40
41
42
        warden::task<std::size_t> read_some(
                warden &w,
                std::span<std::byte>,
                std::optional<std::chrono::nanoseconds> const timeout = {},
                felspar::source_location const & =
                        felspar::source_location::current());

Write to the connection

44
45
46
47
48
49
50
        warden::task<std::size_t> write_some(
                warden &w,
                std::span<std::byte const>,
                std::optional<std::chrono::nanoseconds> const timeout = {},
                felspar::source_location const & =
                        felspar::source_location::current());
    };

Free-standing APIs

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
    inline auto read_some(
            warden &w,
            tls &cnx,
            std::span<std::byte> const s,
            std::optional<std::chrono::nanoseconds> const timeout = {},
            felspar::source_location const &loc =
                    felspar::source_location::current()) {
        return cnx.read_some(w, s, timeout, loc);
    }
    inline auto write_some(
            warden &w,
            tls &cnx,
            std::span<std::byte const> const s,
            std::optional<std::chrono::nanoseconds> const timeout = {},
            felspar::source_location const &loc =
                    felspar::source_location::current()) {
        return cnx.write_some(w, s, timeout, loc);
    }


}