uvco 0.1
Loading...
Searching...
No Matches
stream_server_base.h
Go to the documentation of this file.
1// uvco (c) 2024 Lewin Bormann. See LICENSE for specific terms.
2
3#pragma once
4
5#include <fmt/core.h>
6#include <uv.h>
7
12
13#include <memory>
14
15namespace uvco {
16
19
23template <typename UvStreamType> struct UvStreamInitHelper {
24 static void init(uv_loop_t * /*loop*/, UvStreamType * /*stream*/) {
25 BOOST_ASSERT_MSG(false, "UvStreamInit not specialized for this type");
26 }
27};
28
35template <typename UvStreamType, typename StreamType> class StreamServerBase {
36 struct ConnectionAwaiter_;
37
38public:
44
50 MultiPromise<StreamType> listen(int backlog = 128);
51
53 [[nodiscard]] AddressHandle getSockname() const;
54
61 void close();
62
63protected:
64 explicit StreamServerBase(std::unique_ptr<UvStreamType> socket)
65 : socket_{std::move(socket)} {}
66 std::unique_ptr<UvStreamType> socket_;
67
68private:
70 static void onNewConnection(uv_stream_t *stream, uv_status status);
71};
72
73// Implementation contained in stream_server_base_impl.cc, where it's
74// instantiated for the currently two socket types using it (UnixServer and
75// TcpServer). Include stream_server_base_impl.h to obtain declarations for
76// those specializations.
77
79
80} // namespace uvco
AddressHandle is a light-weight wrapper around a struct / sockaddr_in(6), and is therefore cheap to c...
Definition name_resolution.h:32
Definition multipromise.h:127
StreamServerBase(StreamServerBase &&)=default
StreamServerBase & operator=(StreamServerBase &&)=default
std::unique_ptr< UvStreamType > socket_
Definition stream_server_base.h:66
AddressHandle getSockname() const
Get the address the server is bound to.
Definition stream_server_base_impl.cc:193
MultiPromise< StreamType > listen(int backlog=128)
Definition stream_server_base_impl.cc:144
StreamServerBase(const StreamServerBase &)=delete
StreamServerBase(std::unique_ptr< UvStreamType > socket)
Definition stream_server_base.h:64
StreamServerBase & operator=(const StreamServerBase &)=delete
static void onNewConnection(uv_stream_t *stream, uv_status status)
Called by libuv when a new connection arrives.
Definition stream_server_base_impl.cc:88
~StreamServerBase()
Definition stream_server_base_impl.cc:119
void close()
Definition stream_server_base_impl.cc:125
int uv_status
Result of a libuv operation, an errno error code.
Definition internal_utils.h:22
Definition async_work.cc:18
Definition stream_server_base_impl.cc:32
Definition stream_server_base.h:23
static void init(uv_loop_t *, UvStreamType *)
Definition stream_server_base.h:24