Toolbox
snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
toolbox
net
StreamSock.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_STREAMSOCK_HPP
18
#define TOOLBOX_NET_STREAMSOCK_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
StreamSockServ
:
Sock
{
28
using
Protocol
=
StreamProtocol
;
29
using
Endpoint
=
StreamEndpoint
;
30
31
using
Sock::Sock
;
32
33
StreamSockServ
(
Protocol
protocol, std::error_code&
ec
)
noexcept
34
:
Sock
{
os::socket
(protocol,
ec
), protocol.family()}
35
{
36
}
37
explicit
StreamSockServ
(
Protocol
protocol)
38
:
Sock
{os::socket(protocol), protocol.
family
()}
39
{
40
}
41
StreamSockServ
()
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
52
void
listen
(
int
backlog
, std::error_code&
ec
)
noexcept
{
os::listen
(
get
(),
backlog
,
ec
); }
53
void
listen
(
int
backlog
) {
os::listen
(
get
(),
backlog
); }
54
55
IoSock
accept
(
Endpoint
&
ep
, std::error_code&
ec
)
noexcept
56
{
57
return
IoSock
{
os::accept
(
get
(),
ep
,
ec
),
family
()};
58
}
59
IoSock
accept
(
Endpoint
&
ep
) {
return
IoSock
{
os::accept
(
get
(),
ep
),
family
()}; }
60
};
61
63
struct
StreamSockClnt
:
IoSock
{
64
using
Protocol
=
StreamProtocol
;
65
using
Endpoint
=
StreamEndpoint
;
66
67
using
IoSock::IoSock
;
68
69
StreamSockClnt
(
Protocol
protocol, std::error_code&
ec
)
noexcept
70
:
IoSock
{
os::socket
(protocol,
ec
), protocol.family()}
71
{
72
}
73
explicit
StreamSockClnt
(
Protocol
protocol)
74
:
IoSock
{os::socket(protocol), protocol.
family
()}
75
{
76
}
77
StreamSockClnt
()
noexcept
=
default
;
78
79
// Logically const.
80
void
get_sock_name
(
Endpoint
&
ep
,
std
::error_code&
ec
)
noexcept
81
{
82
os::getsockname
(
get
(),
ep
,
ec
);
83
}
84
void
get_sock_name
(
Endpoint
&
ep
) {
os::getsockname
(
get
(),
ep
); }
85
void
connect
(
const
Endpoint
&
ep
, std::error_code&
ec
)
noexcept
86
{
87
return
os::connect
(
get
(),
ep
,
ec
);
88
}
89
void
connect
(
const
Endpoint
&
ep
) {
return
os::connect
(
get
(),
ep
); }
90
};
91
92
}
// namespace net
93
}
// namespace toolbox
94
95
#endif
// TOOLBOX_NET_STREAMSOCK_HPP
Endpoint.hpp
IoSock.hpp
std
STL namespace.
toolbox::net::StreamEndpoint
BasicEndpoint< StreamProtocol > StreamEndpoint
Definition
Endpoint.hpp:35
toolbox::os::accept
FileHandle accept(int sockfd, sockaddr &addr, socklen_t &addrlen, std::error_code &ec) noexcept
Accept a connection on a socket.
Definition
Socket.hpp:194
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::listen
void listen(int sockfd, int backlog, std::error_code &ec) noexcept
Listen for connections on a socket.
Definition
Socket.hpp:322
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::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::IoSock
Definition
IoSock.hpp:27
toolbox::net::IoSock::IoSock
IoSock() noexcept=default
toolbox::net::Sock
Definition
Socket.hpp:780
toolbox::net::Sock::family
int family() const noexcept
Definition
Socket.hpp:788
toolbox::net::Sock::Sock
Sock() noexcept=default
toolbox::net::StreamProtocol
Definition
Protocol.hpp:52
toolbox::net::StreamSockClnt
Active Client Stream Socket. All state is in base class, so object can be sliced.
Definition
StreamSock.hpp:63
toolbox::net::StreamSockClnt::StreamSockClnt
StreamSockClnt() noexcept=default
toolbox::net::StreamSockClnt::connect
void connect(const Endpoint &ep)
Definition
StreamSock.hpp:89
toolbox::net::StreamSockClnt::StreamSockClnt
StreamSockClnt(Protocol protocol)
Definition
StreamSock.hpp:73
toolbox::net::StreamSockClnt::Endpoint
StreamEndpoint Endpoint
Definition
StreamSock.hpp:65
toolbox::net::StreamSockClnt::get_sock_name
void get_sock_name(Endpoint &ep)
Definition
StreamSock.hpp:84
toolbox::net::StreamSockClnt::get_sock_name
void get_sock_name(Endpoint &ep, std::error_code &ec) noexcept
Definition
StreamSock.hpp:80
toolbox::net::StreamSockClnt::StreamSockClnt
StreamSockClnt(Protocol protocol, std::error_code &ec) noexcept
Definition
StreamSock.hpp:69
toolbox::net::StreamSockClnt::connect
void connect(const Endpoint &ep, std::error_code &ec) noexcept
Definition
StreamSock.hpp:85
toolbox::net::StreamSockServ
Passive Server Stream Socket. All state is in base class, so object can be sliced.
Definition
StreamSock.hpp:27
toolbox::net::StreamSockServ::StreamSockServ
StreamSockServ(Protocol protocol, std::error_code &ec) noexcept
Definition
StreamSock.hpp:33
toolbox::net::StreamSockServ::accept
IoSock accept(Endpoint &ep, std::error_code &ec) noexcept
Definition
StreamSock.hpp:55
toolbox::net::StreamSockServ::listen
void listen(int backlog)
Definition
StreamSock.hpp:53
toolbox::net::StreamSockServ::get_sock_name
void get_sock_name(Endpoint &ep)
Definition
StreamSock.hpp:48
toolbox::net::StreamSockServ::StreamSockServ
StreamSockServ() noexcept=default
toolbox::net::StreamSockServ::Endpoint
StreamEndpoint Endpoint
Definition
StreamSock.hpp:29
toolbox::net::StreamSockServ::listen
void listen(int backlog, std::error_code &ec) noexcept
Definition
StreamSock.hpp:52
toolbox::net::StreamSockServ::get_sock_name
void get_sock_name(Endpoint &ep, std::error_code &ec) noexcept
Definition
StreamSock.hpp:44
toolbox::net::StreamSockServ::bind
void bind(const Endpoint &ep, std::error_code &ec) noexcept
Definition
StreamSock.hpp:49
toolbox::net::StreamSockServ::StreamSockServ
StreamSockServ(Protocol protocol)
Definition
StreamSock.hpp:37
toolbox::net::StreamSockServ::bind
void bind(const Endpoint &ep)
Definition
StreamSock.hpp:50
toolbox::net::StreamSockServ::accept
IoSock accept(Endpoint &ep)
Definition
StreamSock.hpp:59
Generated by
1.9.8