Toolbox
snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
toolbox
net
DgramSock.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_DGRAMSOCK_HPP
18
#define TOOLBOX_NET_DGRAMSOCK_HPP
19
20
#include <
toolbox/net/Endpoint.hpp
>
21
#include <
toolbox/net/IoSock.hpp
>
22
23
namespace
toolbox
{
24
inline
namespace
net {
25
27
struct
DgramSock
:
IoSock
{
28
using
Protocol
=
DgramProtocol
;
29
using
Endpoint
=
DgramEndpoint
;
30
31
using
IoSock::IoSock
;
32
33
DgramSock
(
Protocol
protocol, std::error_code&
ec
)
noexcept
34
:
IoSock
{
os::socket
(protocol,
ec
), protocol.family()}
35
{
36
}
37
explicit
DgramSock
(
Protocol
protocol)
38
:
IoSock
{os::socket(protocol), protocol.
family
()}
39
{
40
}
41
DgramSock
()
noexcept
=
default
;
42
43
// Logically const.
44
void
get_sock_name
(
Endpoint
&
ep
,
std
::error_code&
ec
)
noexcept
45
{
46
os::getsockname
(
get
(),
ep
,
ec
);
47
}
48
void
get_sock_name
(
Endpoint
&
ep
) {
os::getsockname
(
get
(),
ep
); }
49
void
bind
(
const
Endpoint
&
ep
, std::error_code&
ec
)
noexcept
{
os::bind
(
get
(),
ep
,
ec
); }
50
void
bind
(
const
Endpoint
&
ep
) {
os::bind
(
get
(),
ep
); }
51
void
connect
(
const
Endpoint
&
ep
, std::error_code&
ec
)
noexcept
52
{
53
return
os::connect
(
get
(),
ep
,
ec
);
54
}
55
void
connect
(
const
Endpoint
&
ep
) {
return
os::connect
(
get
(),
ep
); }
56
57
ssize_t
recvfrom
(
void
*
buf
, std::size_t
len
,
int
flags
,
Endpoint
&
ep
,
58
std::error_code&
ec
)
noexcept
59
{
60
return
os::recvfrom
(
get
(),
buf
,
len
,
flags
,
ep
,
ec
);
61
}
62
std::size_t
recvfrom
(
void
*
buf
, std::size_t
len
,
int
flags
,
Endpoint
&
ep
)
63
{
64
return
os::recvfrom
(
get
(),
buf
,
len
,
flags
,
ep
);
65
}
66
67
ssize_t
recvfrom
(
MutableBuffer
buf
,
int
flags
,
Endpoint
&
ep
, std::error_code&
ec
)
noexcept
68
{
69
return
os::recvfrom
(
get
(),
buf
,
flags
,
ep
,
ec
);
70
}
71
std::size_t
recvfrom
(
MutableBuffer
buf
,
int
flags
,
Endpoint
&
ep
)
72
{
73
return
os::recvfrom
(
get
(),
buf
,
flags
,
ep
);
74
}
75
76
ssize_t
sendto
(
const
void
*
buf
, std::size_t
len
,
int
flags
,
const
Endpoint
&
ep
,
77
std::error_code&
ec
)
noexcept
78
{
79
return
os::sendto
(
get
(),
buf
,
len
,
flags
,
ep
,
ec
);
80
}
81
std::size_t
sendto
(
const
void
*
buf
, std::size_t
len
,
int
flags
,
const
Endpoint
&
ep
)
82
{
83
return
os::sendto
(
get
(),
buf
,
len
,
flags
,
ep
);
84
}
85
86
ssize_t
sendto
(
ConstBuffer
buf
,
int
flags
,
const
Endpoint
&
ep
, std::error_code&
ec
)
noexcept
87
{
88
return
os::sendto
(
get
(),
buf
,
flags
,
ep
,
ec
);
89
}
90
std::size_t
sendto
(
ConstBuffer
buf
,
int
flags
,
const
Endpoint
&
ep
)
91
{
92
return
os::sendto
(
get
(),
buf
,
flags
,
ep
);
93
}
94
};
95
96
}
// namespace net
97
}
// namespace toolbox
98
99
#endif
// TOOLBOX_NET_DGRAMSOCK_HPP
Endpoint.hpp
IoSock.hpp
std
STL namespace.
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::DgramEndpoint
BasicEndpoint< DgramProtocol > DgramEndpoint
Definition
Endpoint.hpp:34
toolbox::os::bind
void bind(int sockfd, const sockaddr &addr, socklen_t addrlen, std::error_code &ec) noexcept
Bind a name to a socket.
Definition
Socket.hpp:261
toolbox::os::recvfrom
ssize_t recvfrom(int sockfd, void *buf, std::size_t len, int flags, sockaddr &addr, socklen_t &addrlen, std::error_code &ec) noexcept
Receive a message from a socket.
Definition
Socket.hpp:386
toolbox::os::getsockname
void getsockname(int sockfd, sockaddr &addr, socklen_t &addrlen, std::error_code &ec) noexcept
Get the socket name.
Definition
Socket.hpp:538
toolbox::os::socket
FileHandle socket(int family, int type, int protocol, std::error_code &ec) noexcept
Create an endpoint for communication.
Definition
Socket.hpp:124
toolbox::os::connect
void connect(int sockfd, const sockaddr &addr, socklen_t addrlen, std::error_code &ec) noexcept
Initiate a connection on a socket.
Definition
Socket.hpp:291
toolbox::os::sendto
ssize_t sendto(int sockfd, const void *buf, std::size_t len, int flags, const sockaddr &addr, socklen_t addrlen, std::error_code &ec) noexcept
Send a message on a socket.
Definition
Socket.hpp:483
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::net::DgramProtocol
Definition
Protocol.hpp:25
toolbox::DgramSock
Connectionless Datagram Socket. All state is in base class, so object can be sliced.
Definition
DgramSock.hpp:27
toolbox::net::DgramSock::connect
void connect(const Endpoint &ep, std::error_code &ec) noexcept
Definition
DgramSock.hpp:51
toolbox::net::DgramSock::bind
void bind(const Endpoint &ep, std::error_code &ec) noexcept
Definition
DgramSock.hpp:49
toolbox::net::DgramSock::Endpoint
DgramEndpoint Endpoint
Definition
DgramSock.hpp:29
toolbox::net::DgramSock::DgramSock
DgramSock(Protocol protocol)
Definition
DgramSock.hpp:37
toolbox::net::DgramSock::DgramSock
DgramSock(Protocol protocol, std::error_code &ec) noexcept
Definition
DgramSock.hpp:33
toolbox::net::DgramSock::sendto
ssize_t sendto(const void *buf, std::size_t len, int flags, const Endpoint &ep, std::error_code &ec) noexcept
Definition
DgramSock.hpp:76
toolbox::net::DgramSock::sendto
std::size_t sendto(const void *buf, std::size_t len, int flags, const Endpoint &ep)
Definition
DgramSock.hpp:81
toolbox::net::DgramSock::DgramSock
DgramSock() noexcept=default
toolbox::net::DgramSock::get_sock_name
void get_sock_name(Endpoint &ep, std::error_code &ec) noexcept
Definition
DgramSock.hpp:44
toolbox::net::DgramSock::connect
void connect(const Endpoint &ep)
Definition
DgramSock.hpp:55
toolbox::net::DgramSock::recvfrom
ssize_t recvfrom(void *buf, std::size_t len, int flags, Endpoint &ep, std::error_code &ec) noexcept
Definition
DgramSock.hpp:57
toolbox::net::DgramSock::sendto
ssize_t sendto(ConstBuffer buf, int flags, const Endpoint &ep, std::error_code &ec) noexcept
Definition
DgramSock.hpp:86
toolbox::net::DgramSock::recvfrom
std::size_t recvfrom(void *buf, std::size_t len, int flags, Endpoint &ep)
Definition
DgramSock.hpp:62
toolbox::net::DgramSock::recvfrom
std::size_t recvfrom(MutableBuffer buf, int flags, Endpoint &ep)
Definition
DgramSock.hpp:71
toolbox::net::DgramSock::sendto
std::size_t sendto(ConstBuffer buf, int flags, const Endpoint &ep)
Definition
DgramSock.hpp:90
toolbox::net::DgramSock::get_sock_name
void get_sock_name(Endpoint &ep)
Definition
DgramSock.hpp:48
toolbox::net::DgramSock::bind
void bind(const Endpoint &ep)
Definition
DgramSock.hpp:50
toolbox::net::DgramSock::recvfrom
ssize_t recvfrom(MutableBuffer buf, int flags, Endpoint &ep, std::error_code &ec) noexcept
Definition
DgramSock.hpp:67
toolbox::IoSock
Definition
IoSock.hpp:27
toolbox::net::IoSock::IoSock
IoSock() noexcept=default
toolbox::net::Sock::family
int family() const noexcept
Definition
Socket.hpp:788
Generated by
1.9.8