AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
tcpStream.hpp
1/*
2 ANCH Framework: ANother C++ Hack is a C++ framework based on C++23 standard
3 Copyright (C) 2012 Vincent Lachenal
4
5 This file is part of ANCH Framework.
6
7 ANCH Framework is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 ANCH Framework is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with ANCH Framework. If not, see <https://www.gnu.org/licenses/>.
19*/
20#pragma once
21
22#include "anch-network-export.hpp"
23
24#include <cstddef>
25#include <string>
26
27#include "cutils/iostream.hpp"
28#include "network/socket.hpp"
29
30namespace anch::network {
31
40 struct ANCH_NETWORK_EXPORT SocketHolder {
43 };
44
59 class ANCH_NETWORK_EXPORT TcpStream: private anch::network::SocketHolder, public anch::cutils::CIOStream {
60
61 // Attributes +
62 public:
64 static constexpr std::size_t DEFAULT_BUFFER_SIZE = 8192;
65 // Attributes -
66
67 // Constructors +
68 public:
78 TcpStream(const std::string& host, uint16_t port, std::size_t bufSize = DEFAULT_BUFFER_SIZE);
79
86 explicit TcpStream(anch::network::Socket&& socket, std::size_t bufSize = DEFAULT_BUFFER_SIZE);
87
91 TcpStream(const TcpStream&) = delete;
92
96 TcpStream(TcpStream&&) = delete;
97 // Constructors -
98
99 // Destructor +
100 public:
104 virtual ~TcpStream() noexcept;
105 // Destructor -
106
107 // Methods +
108 public:
117 void shutdown(anch::network::Direction how = anch::network::Direction::TRANSMISSION);
118
125 // Methods -
126
127 private:
133 void init(std::size_t bufSize);
134
135 };
136
137} // anch::network
Definition iostream.hpp:325
Network socket (POSIX).
Definition socket.hpp:63
TcpStream(const std::string &host, uint16_t port, std::size_t bufSize=DEFAULT_BUFFER_SIZE)
static constexpr std::size_t DEFAULT_BUFFER_SIZE
Definition tcpStream.hpp:64
anch::network::Socket & getSocket() noexcept
TcpStream(anch::network::Socket &&socket, std::size_t bufSize=DEFAULT_BUFFER_SIZE)
virtual ~TcpStream() noexcept
TcpStream(const TcpStream &)=delete
TcpStream(TcpStream &&)=delete
void shutdown(anch::network::Direction how=anch::network::Direction::TRANSMISSION)
Network namespace.
Definition address.hpp:30
Direction
Definition socket.hpp:39
AnCH framework base namespace.
Definition app.hpp:30
Socket owner base class of TcpStream.
Definition tcpStream.hpp:40
anch::network::Socket _socket
Definition tcpStream.hpp:42