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
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
89
template
<
typename
ProtocolT>
90
inline
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
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:90
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:146
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:178
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:158
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:450
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:338
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:354
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:92
toolbox
Definition
Benchmark.cpp:26
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:77
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:55
toolbox::net::IoSock::recv
std::size_t recv(MutableBuffer buf, int flags)
Definition
IoSock.hpp:59
toolbox::net::IoSock::write
ssize_t write(const void *buf, std::size_t len, std::error_code &ec) noexcept
Definition
IoSock.hpp:61
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:67
toolbox::net::IoSock::send
ssize_t send(const void *buf, std::size_t len, int flags, std::error_code &ec) noexcept
Definition
IoSock.hpp:73
toolbox::net::IoSock::send
ssize_t send(ConstBuffer buf, int flags, std::error_code &ec) noexcept
Definition
IoSock.hpp:82
toolbox::net::IoSock::write
std::size_t write(const void *buf, std::size_t len)
Definition
IoSock.hpp:65
toolbox::net::IoSock::IoSock
IoSock() noexcept=default
toolbox::net::IoSock::write
std::size_t write(ConstBuffer buf)
Definition
IoSock.hpp:71
toolbox::net::IoSock::send
std::size_t send(ConstBuffer buf, int flags)
Definition
IoSock.hpp:86
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:780
toolbox::net::Sock::family
int family() const noexcept
Definition
Socket.hpp:788
toolbox::net::Sock::Sock
Sock() noexcept=default
Generated by
1.9.8