Toolbox snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
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
22
23namespace toolbox {
24inline namespace net {
25
27struct DgramSock : IoSock {
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 }
42
43 // Logically const.
44 void get_sock_name(Endpoint& ep, std::error_code& ec) noexcept
45 {
47 }
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 }
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
STL namespace.
boost::asio::const_buffer ConstBuffer
Definition Buffer.hpp:28
boost::asio::mutable_buffer MutableBuffer
Definition Buffer.hpp:29
BasicEndpoint< DgramProtocol > DgramEndpoint
Definition Endpoint.hpp:34
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
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
void getsockname(int sockfd, sockaddr &addr, socklen_t &addrlen, std::error_code &ec) noexcept
Get the socket name.
Definition Socket.hpp:538
FileHandle socket(int family, int type, int protocol, std::error_code &ec) noexcept
Create an endpoint for communication.
Definition Socket.hpp:124
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
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
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:92
Connectionless Datagram Socket. All state is in base class, so object can be sliced.
Definition DgramSock.hpp:27
void connect(const Endpoint &ep, std::error_code &ec) noexcept
Definition DgramSock.hpp:51
void bind(const Endpoint &ep, std::error_code &ec) noexcept
Definition DgramSock.hpp:49
DgramEndpoint Endpoint
Definition DgramSock.hpp:29
DgramSock(Protocol protocol)
Definition DgramSock.hpp:37
DgramSock(Protocol protocol, std::error_code &ec) noexcept
Definition DgramSock.hpp:33
ssize_t sendto(const void *buf, std::size_t len, int flags, const Endpoint &ep, std::error_code &ec) noexcept
Definition DgramSock.hpp:76
std::size_t sendto(const void *buf, std::size_t len, int flags, const Endpoint &ep)
Definition DgramSock.hpp:81
DgramSock() noexcept=default
void get_sock_name(Endpoint &ep, std::error_code &ec) noexcept
Definition DgramSock.hpp:44
void connect(const Endpoint &ep)
Definition DgramSock.hpp:55
ssize_t recvfrom(void *buf, std::size_t len, int flags, Endpoint &ep, std::error_code &ec) noexcept
Definition DgramSock.hpp:57
ssize_t sendto(ConstBuffer buf, int flags, const Endpoint &ep, std::error_code &ec) noexcept
Definition DgramSock.hpp:86
std::size_t recvfrom(void *buf, std::size_t len, int flags, Endpoint &ep)
Definition DgramSock.hpp:62
std::size_t recvfrom(MutableBuffer buf, int flags, Endpoint &ep)
Definition DgramSock.hpp:71
std::size_t sendto(ConstBuffer buf, int flags, const Endpoint &ep)
Definition DgramSock.hpp:90
void get_sock_name(Endpoint &ep)
Definition DgramSock.hpp:48
void bind(const Endpoint &ep)
Definition DgramSock.hpp:50
ssize_t recvfrom(MutableBuffer buf, int flags, Endpoint &ep, std::error_code &ec) noexcept
Definition DgramSock.hpp:67
IoSock() noexcept=default
int family() const noexcept
Definition Socket.hpp:788