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 recvmsg(msghdr& msg, int flags, std::error_code& ec) noexcept
56 {
57 return os::recvmsg(get(), msg, flags, ec);
58 }
59
60 std::size_t recvmsg(msghdr& msg, int flags)
61 {
62 return os::recvmsg(get(), msg, flags);
63 }
64
65 ssize_t recv(MutableBuffer buf, int flags, std::error_code& ec) noexcept
66 {
67 return os::recv(get(), buf, flags, ec);
68 }
69 std::size_t recv(MutableBuffer buf, int flags) { return os::recv(get(), buf, flags); }
70
71 ssize_t write(const void* buf, std::size_t len, std::error_code& ec) noexcept
72 {
73 return os::write(get(), buf, len, ec);
74 }
75 std::size_t write(const void* buf, std::size_t len) { return os::write(get(), buf, len); }
76
77 ssize_t write(ConstBuffer buf, std::error_code& ec) noexcept
78 {
79 return os::write(get(), buf, ec);
80 }
81 std::size_t write(ConstBuffer buf) { return os::write(get(), buf); }
82
83 ssize_t send(const void* buf, std::size_t len, int flags, std::error_code& ec) noexcept
84 {
85 return os::send(get(), buf, len, flags, ec);
86 }
87 std::size_t send(const void* buf, std::size_t len, int flags)
88 {
89 return os::send(get(), buf, len, flags);
90 }
91
92 ssize_t send(ConstBuffer buf, int flags, std::error_code& ec) noexcept
93 {
94 return os::send(get(), buf, flags, ec);
95 }
96 std::size_t send(ConstBuffer buf, int flags) { return os::send(get(), buf, flags); }
97};
98
99template <typename ProtocolT>
100inline std::pair<IoSock, IoSock> socketpair(ProtocolT protocol)
101{
102 auto socks = os::socketpair(protocol);
103 return {IoSock{std::move(socks.first), protocol.family()},
104 IoSock{std::move(socks.second), protocol.family()}};
105}
106
107} // namespace net
108} // namespace toolbox
109
110#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:100
ssize_t recvmsg(int sockfd, msghdr &msg, int flags, std::error_code &ec) noexcept
Definition Socket.hpp:386
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:159
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:469
void shutdown(int sockfd, int how, std::error_code &ec) noexcept
Shut-down part of a full-duplex connection.
Definition Socket.hpp:339
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:355
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:97
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:87
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:65
std::size_t recv(MutableBuffer buf, int flags)
Definition IoSock.hpp:69
ssize_t write(const void *buf, std::size_t len, std::error_code &ec) noexcept
Definition IoSock.hpp:71
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:77
ssize_t send(const void *buf, std::size_t len, int flags, std::error_code &ec) noexcept
Definition IoSock.hpp:83
ssize_t send(ConstBuffer buf, int flags, std::error_code &ec) noexcept
Definition IoSock.hpp:92
std::size_t write(const void *buf, std::size_t len)
Definition IoSock.hpp:75
std::size_t recvmsg(msghdr &msg, int flags)
Definition IoSock.hpp:60
IoSock() noexcept=default
std::size_t write(ConstBuffer buf)
Definition IoSock.hpp:81
std::size_t send(ConstBuffer buf, int flags)
Definition IoSock.hpp:96
ssize_t recvmsg(msghdr &msg, int flags, std::error_code &ec) noexcept
Definition IoSock.hpp:55
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:833
Sock() noexcept=default