uvco 0.1
Loading...
Searching...
No Matches
tcp_stream.h
Go to the documentation of this file.
1// uvco (c) 2023 Lewin Bormann. See LICENSE for specific terms.
2
3#pragma once
4
5#include <uv.h>
6
7#include <boost/assert.hpp>
8#include <fmt/format.h>
9
12#include "uvco/stream.h"
13
14#include <memory>
15#include <sys/socket.h>
16#include <utility>
17
18namespace uvco {
19
23class TcpStream : public StreamBase {
24public:
25 explicit TcpStream(std::unique_ptr<uv_tcp_t> tcp)
26 : StreamBase{std::move(tcp)} {}
27 TcpStream(const TcpStream &) = delete;
28 TcpStream(TcpStream &&) = default;
29 TcpStream &operator=(const TcpStream &) = delete;
31
32 ~TcpStream() override = default;
33
35 [[nodiscard]] AddressHandle getPeerName() const;
36
38 [[nodiscard]] AddressHandle getSockName() const;
39
42 [[nodiscard]] Promise<void> closeReset();
43
45 void keepAlive(bool enable, unsigned int delay = 10);
46
48 void noDelay(bool enable);
49};
50
51} // namespace uvco
AddressHandle is a light-weight wrapper around a struct sockaddr_in(6), and is therefore cheap to cop...
Definition name_resolution.h:38
Definition promise.h:76
A plain stream, permitting reading, writing, and closing.
Definition stream.h:32
Definition tcp_stream.h:23
AddressHandle getSockName() const
Return bound address of socket.
Definition tcp_stream.cc:22
void keepAlive(bool enable, unsigned int delay=10)
Set keep-alive delay in seconds.
Definition tcp_stream.cc:40
TcpStream(std::unique_ptr< uv_tcp_t > tcp)
Definition tcp_stream.h:25
TcpStream & operator=(const TcpStream &)=delete
TcpStream(TcpStream &&)=default
TcpStream & operator=(TcpStream &&)=default
Promise< void > closeReset()
Definition tcp_stream.cc:17
TcpStream(const TcpStream &)=delete
~TcpStream() override=default
AddressHandle getPeerName() const
Return address of peer.
Definition tcp_stream.cc:31
void noDelay(bool enable)
Enable Nagle's algorithm.
Definition tcp_stream.cc:44
Definition async_work.cc:17