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