Toolbox
snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
toolbox
net
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
20
#include <
toolbox/net/Socket.hpp
>
21
22
namespace
toolbox
{
23
inline
namespace
net {
24
27
struct
IoSock
:
Sock
{
28
using
Sock::Sock
;
29
30
IoSock
()
noexcept
=
default
;
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
96
template
<
typename
ProtocolT>
97
inline
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
Socket.hpp
toolbox::io::ConstBuffer
boost::asio::const_buffer ConstBuffer
Definition
Buffer.hpp:28
toolbox::io::MutableBuffer
boost::asio::mutable_buffer MutableBuffer
Definition
Buffer.hpp:29
toolbox::net::socketpair
std::pair< IoSock, IoSock > socketpair(ProtocolT protocol)
Definition
IoSock.hpp:97
toolbox::os::recvmsg
ssize_t recvmsg(int sockfd, msghdr &msg, int flags, std::error_code &ec) noexcept
Definition
Socket.hpp:407
toolbox::os::read
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
toolbox::os::write
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
toolbox::os::socketpair
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
toolbox::os::send
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
toolbox::os::shutdown
void shutdown(int sockfd, int how, std::error_code &ec) noexcept
Shut-down part of a full-duplex connection.
Definition
Socket.hpp:360
toolbox::os::recv
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
toolbox::util::get
constexpr const auto & get(const detail::Struct< detail::Member< TagsT, ValuesT >... > &s, TagT tag={})
Definition
Struct.hpp:110
toolbox::util::bind
constexpr auto bind() noexcept
Definition
Slot.hpp:97
toolbox
Definition
Benchmark.cpp:27
toolbox::IoSock
Definition
IoSock.hpp:27
toolbox::net::IoSock::recv
std::size_t recv(void *buf, std::size_t len, int flags)
Definition
IoSock.hpp:50
toolbox::net::IoSock::send
std::size_t send(const void *buf, std::size_t len, int flags)
Definition
IoSock.hpp:84
toolbox::net::IoSock::shutdown
void shutdown(int how)
Definition
IoSock.hpp:32
toolbox::net::IoSock::read
std::size_t read(void *buf, std::size_t len)
Definition
IoSock.hpp:38
toolbox::net::IoSock::recv
ssize_t recv(void *buf, std::size_t len, int flags, std::error_code &ec) noexcept
Definition
IoSock.hpp:46
toolbox::net::IoSock::recv
ssize_t recv(MutableBuffer buf, int flags, std::error_code &ec) noexcept
Definition
IoSock.hpp:62
toolbox::net::IoSock::recv
std::size_t recv(MutableBuffer buf, int flags)
Definition
IoSock.hpp:66
toolbox::net::IoSock::write
ssize_t write(const void *buf, std::size_t len, std::error_code &ec) noexcept
Definition
IoSock.hpp:68
toolbox::net::IoSock::read
ssize_t read(void *buf, std::size_t len, std::error_code &ec) noexcept
Definition
IoSock.hpp:34
toolbox::net::IoSock::write
ssize_t write(ConstBuffer buf, std::error_code &ec) noexcept
Definition
IoSock.hpp:74
toolbox::net::IoSock::send
ssize_t send(const void *buf, std::size_t len, int flags, std::error_code &ec) noexcept
Definition
IoSock.hpp:80
toolbox::net::IoSock::send
ssize_t send(ConstBuffer buf, int flags, std::error_code &ec) noexcept
Definition
IoSock.hpp:89
toolbox::net::IoSock::write
std::size_t write(const void *buf, std::size_t len)
Definition
IoSock.hpp:72
toolbox::net::IoSock::recvmsg
std::size_t recvmsg(msghdr &msg, int flags)
Definition
IoSock.hpp:60
toolbox::net::IoSock::IoSock
IoSock() noexcept=default
toolbox::net::IoSock::write
std::size_t write(ConstBuffer buf)
Definition
IoSock.hpp:78
toolbox::net::IoSock::send
std::size_t send(ConstBuffer buf, int flags)
Definition
IoSock.hpp:93
toolbox::net::IoSock::recvmsg
ssize_t recvmsg(msghdr &msg, int flags, std::error_code &ec) noexcept
Definition
IoSock.hpp:55
toolbox::net::IoSock::read
std::size_t read(MutableBuffer buf)
Definition
IoSock.hpp:44
toolbox::net::IoSock::read
ssize_t read(MutableBuffer buf, std::error_code &ec) noexcept
Definition
IoSock.hpp:40
toolbox::Sock
Definition
Socket.hpp:846
toolbox::net::Sock::family
int family() const noexcept
Definition
Socket.hpp:854
toolbox::net::Sock::Sock
Sock() noexcept=default
Generated by
1.9.8