Toolbox snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
StreamSock.hpp
Go to the documentation of this file.
1// The Reactive C++ Toolbox.
2// Copyright (C) 2013-2019 Swirly Cloud Limited
3// Copyright (C) 2021 Reactive Markets Limited
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17#ifndef TOOLBOX_NET_STREAMSOCK_HPP
18#define TOOLBOX_NET_STREAMSOCK_HPP
19
22
23namespace toolbox {
24inline namespace net {
25
30
31 using Sock::Sock;
32
33 StreamSockServ(Protocol protocol, std::error_code& ec) noexcept
34 : Sock{os::socket(protocol, ec), protocol.family()}
35 {
36 }
37 explicit StreamSockServ(Protocol protocol)
38 : Sock{os::socket(protocol), protocol.family()}
39 {
40 }
42
43 // Logically const.
44 void get_sock_name(Endpoint& ep, std::error_code& ec) noexcept
45 {
47 }
49 void bind(const Endpoint& ep, std::error_code& ec) noexcept { os::bind(get(), ep, ec); }
50 void bind(const Endpoint& ep) { os::bind(get(), ep); }
51
52 void listen(int backlog, std::error_code& ec) noexcept { os::listen(get(), backlog, ec); }
53 void listen(int backlog) { os::listen(get(), backlog); }
54
55 IoSock accept(Endpoint& ep, std::error_code& ec) noexcept
56 {
57 return IoSock{os::accept(get(), ep, ec), family()};
58 }
60};
61
66
67 using IoSock::IoSock;
68
69 StreamSockClnt(Protocol protocol, std::error_code& ec) noexcept
70 : IoSock{os::socket(protocol, ec), protocol.family()}
71 {
72 }
73 explicit StreamSockClnt(Protocol protocol)
74 : IoSock{os::socket(protocol), protocol.family()}
75 {
76 }
78
79 // Logically const.
80 void get_sock_name(Endpoint& ep, std::error_code& ec) noexcept
81 {
83 }
85 void connect(const Endpoint& ep, std::error_code& ec) noexcept
86 {
87 return os::connect(get(), ep, ec);
88 }
89 void connect(const Endpoint& ep) { return os::connect(get(), ep); }
90};
91
92} // namespace net
93} // namespace toolbox
94
95#endif // TOOLBOX_NET_STREAMSOCK_HPP
STL namespace.
BasicEndpoint< StreamProtocol > StreamEndpoint
Definition Endpoint.hpp:35
FileHandle accept(int sockfd, sockaddr &addr, socklen_t &addrlen, std::error_code &ec) noexcept
Accept a connection on a socket.
Definition Socket.hpp:194
void bind(int sockfd, const sockaddr &addr, socklen_t addrlen, std::error_code &ec) noexcept
Bind a name to a socket.
Definition Socket.hpp:261
void listen(int sockfd, int backlog, std::error_code &ec) noexcept
Listen for connections on a socket.
Definition Socket.hpp:322
void getsockname(int sockfd, sockaddr &addr, socklen_t &addrlen, std::error_code &ec) noexcept
Get the socket name.
Definition Socket.hpp:538
FileHandle socket(int family, int type, int protocol, std::error_code &ec) noexcept
Create an endpoint for communication.
Definition Socket.hpp:124
void connect(int sockfd, const sockaddr &addr, socklen_t addrlen, std::error_code &ec) noexcept
Initiate a connection on a socket.
Definition Socket.hpp:291
constexpr const auto & get(const detail::Struct< detail::Member< TagsT, ValuesT >... > &s, TagT tag={})
Definition Struct.hpp:110
constexpr auto bind() noexcept
Definition Slot.hpp:92
IoSock() noexcept=default
int family() const noexcept
Definition Socket.hpp:788
Sock() noexcept=default
Active Client Stream Socket. All state is in base class, so object can be sliced.
StreamSockClnt() noexcept=default
void connect(const Endpoint &ep)
StreamSockClnt(Protocol protocol)
void get_sock_name(Endpoint &ep)
void get_sock_name(Endpoint &ep, std::error_code &ec) noexcept
StreamSockClnt(Protocol protocol, std::error_code &ec) noexcept
void connect(const Endpoint &ep, std::error_code &ec) noexcept
Passive Server Stream Socket. All state is in base class, so object can be sliced.
StreamSockServ(Protocol protocol, std::error_code &ec) noexcept
IoSock accept(Endpoint &ep, std::error_code &ec) noexcept
void get_sock_name(Endpoint &ep)
StreamSockServ() noexcept=default
void listen(int backlog, std::error_code &ec) noexcept
void get_sock_name(Endpoint &ep, std::error_code &ec) noexcept
void bind(const Endpoint &ep, std::error_code &ec) noexcept
StreamSockServ(Protocol protocol)
void bind(const Endpoint &ep)
IoSock accept(Endpoint &ep)