Toolbox snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
IoSock.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_IOSOCK_HPP
18#define TOOLBOX_NET_IOSOCK_HPP
19
21
22namespace toolbox {
23inline namespace net {
24
27struct IoSock : Sock {
28 using Sock::Sock;
29
31
32 void shutdown(int how) { return os::shutdown(get(), how); }
33
34 ssize_t read(void* buf, std::size_t len, std::error_code& ec) noexcept
35 {
36 return os::read(get(), buf, len, ec);
37 }
38 std::size_t read(void* buf, std::size_t len) { return os::read(get(), buf, len); }
39
40 ssize_t read(MutableBuffer buf, std::error_code& ec) noexcept
41 {
42 return os::read(get(), buf, ec);
43 }
44 std::size_t read(MutableBuffer buf) { return os::read(get(), buf); }
45
46 ssize_t recv(void* buf, std::size_t len, int flags, std::error_code& ec) noexcept
47 {
48 return os::recv(get(), buf, len, flags, ec);
49 }
50 std::size_t recv(void* buf, std::size_t len, int flags)
51 {
52 return os::recv(get(), buf, len, flags);
53 }
54
55 ssize_t recv(MutableBuffer buf, int flags, std::error_code& ec) noexcept
56 {
57 return os::recv(get(), buf, flags, ec);
58 }
59 std::size_t recv(MutableBuffer buf, int flags) { return os::recv(get(), buf, flags); }
60
61 ssize_t write(const void* buf, std::size_t len, std::error_code& ec) noexcept
62 {
63 return os::write(get(), buf, len, ec);
64 }
65 std::size_t write(const void* buf, std::size_t len) { return os::write(get(), buf, len); }
66
67 ssize_t write(ConstBuffer buf, std::error_code& ec) noexcept
68 {
69 return os::write(get(), buf, ec);
70 }
71 std::size_t write(ConstBuffer buf) { return os::write(get(), buf); }
72
73 ssize_t send(const void* buf, std::size_t len, int flags, std::error_code& ec) noexcept
74 {
75 return os::send(get(), buf, len, flags, ec);
76 }
77 std::size_t send(const void* buf, std::size_t len, int flags)
78 {
79 return os::send(get(), buf, len, flags);
80 }
81
82 ssize_t send(ConstBuffer buf, int flags, std::error_code& ec) noexcept
83 {
84 return os::send(get(), buf, flags, ec);
85 }
86 std::size_t send(ConstBuffer buf, int flags) { return os::send(get(), buf, flags); }
87};
88
89template <typename ProtocolT>
90inline std::pair<IoSock, IoSock> socketpair(ProtocolT protocol)
91{
92 auto socks = os::socketpair(protocol);
93 return {IoSock{std::move(socks.first), protocol.family()},
94 IoSock{std::move(socks.second), protocol.family()}};
95}
96
97} // namespace net
98} // namespace toolbox
99
100#endif // TOOLBOX_NET_IOSOCK_HPP
boost::asio::const_buffer ConstBuffer
Definition Buffer.hpp:28
boost::asio::mutable_buffer MutableBuffer
Definition Buffer.hpp:29
std::pair< IoSock, IoSock > socketpair(ProtocolT protocol)
Definition IoSock.hpp:90
ssize_t read(int fd, void *buf, std::size_t len, std::error_code &ec) noexcept
Read from a file descriptor.
Definition File.hpp:146
ssize_t write(int fd, const void *buf, std::size_t len, std::error_code &ec) noexcept
Write to a file descriptor.
Definition File.hpp:178
std::pair< FileHandle, FileHandle > socketpair(int family, int type, int protocol, std::error_code &ec) noexcept
Create a pair of connected sockets.
Definition Socket.hpp:158
ssize_t send(int sockfd, const void *buf, std::size_t len, int flags, std::error_code &ec) noexcept
Send a message on a socket.
Definition Socket.hpp:450
void shutdown(int sockfd, int how, std::error_code &ec) noexcept
Shut-down part of a full-duplex connection.
Definition Socket.hpp:338
ssize_t recv(int sockfd, void *buf, std::size_t len, int flags, std::error_code &ec) noexcept
Receive a message from a socket.
Definition Socket.hpp:354
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
std::size_t recv(void *buf, std::size_t len, int flags)
Definition IoSock.hpp:50
std::size_t send(const void *buf, std::size_t len, int flags)
Definition IoSock.hpp:77
void shutdown(int how)
Definition IoSock.hpp:32
std::size_t read(void *buf, std::size_t len)
Definition IoSock.hpp:38
ssize_t recv(void *buf, std::size_t len, int flags, std::error_code &ec) noexcept
Definition IoSock.hpp:46
ssize_t recv(MutableBuffer buf, int flags, std::error_code &ec) noexcept
Definition IoSock.hpp:55
std::size_t recv(MutableBuffer buf, int flags)
Definition IoSock.hpp:59
ssize_t write(const void *buf, std::size_t len, std::error_code &ec) noexcept
Definition IoSock.hpp:61
ssize_t read(void *buf, std::size_t len, std::error_code &ec) noexcept
Definition IoSock.hpp:34
ssize_t write(ConstBuffer buf, std::error_code &ec) noexcept
Definition IoSock.hpp:67
ssize_t send(const void *buf, std::size_t len, int flags, std::error_code &ec) noexcept
Definition IoSock.hpp:73
ssize_t send(ConstBuffer buf, int flags, std::error_code &ec) noexcept
Definition IoSock.hpp:82
std::size_t write(const void *buf, std::size_t len)
Definition IoSock.hpp:65
IoSock() noexcept=default
std::size_t write(ConstBuffer buf)
Definition IoSock.hpp:71
std::size_t send(ConstBuffer buf, int flags)
Definition IoSock.hpp:86
std::size_t read(MutableBuffer buf)
Definition IoSock.hpp:44
ssize_t read(MutableBuffer buf, std::error_code &ec) noexcept
Definition IoSock.hpp:40
int family() const noexcept
Definition Socket.hpp:788
Sock() noexcept=default