CppWAMP
C++11 client library for the WAMP protocol
udspath.hpp
Go to the documentation of this file.
1 /*------------------------------------------------------------------------------
2  Copyright Butterfly Energy Systems 2014-2015, 2022.
3  Distributed under the Boost Software License, Version 1.0.
4  http://www.boost.org/LICENSE_1_0.txt
5 ------------------------------------------------------------------------------*/
6 
7 #ifndef CPPWAMP_UDSPATH_HPP
8 #define CPPWAMP_UDSPATH_HPP
9 
10 //------------------------------------------------------------------------------
14 //------------------------------------------------------------------------------
15 
16 #include <string>
17 #include "api.hpp"
18 #include "rawsockoptions.hpp"
19 #include "internal/socketoptions.hpp"
20 
21 // Forward declaration
22 namespace boost { namespace asio { namespace local { class stream_protocol; }}}
23 
24 namespace wamp
25 {
26 
27 namespace internal { class UdsOpener; } // Forward declaration
28 
29 //------------------------------------------------------------------------------
38 //------------------------------------------------------------------------------
39 class CPPWAMP_API UdsOptions
40 {
41 public:
43  UdsOptions& withBroadcast(bool enabled = true);
44 
46  UdsOptions& withDebug(bool enabled = true);
47 
49  UdsOptions& withDoNotRoute(bool enabled = true);
50 
52  UdsOptions& withKeepAlive(bool enabled = true);
53 
55  UdsOptions& withLinger(bool enabled, int timeout);
56 
58  UdsOptions& withOutOfBandInline(bool enabled);
59 
61  UdsOptions& withReceiveBufferSize(int size);
62 
64  UdsOptions& withReceiveLowWatermark(int size);
65 
67  UdsOptions& withReuseAddress(bool enabled = true);
68 
70  UdsOptions& withSendBufferSize(int size);
71 
73  UdsOptions& withSendLowWatermark(int size);
74 
75 private:
76  template <typename TOption, typename... TArgs>
77  UdsOptions& set(TArgs... args);
78 
79  template <typename TSocket> void applyTo(TSocket& socket) const;
80 
81  internal::SocketOptionList<boost::asio::local::stream_protocol> options_;
82 
83  friend class internal::UdsOpener;
84 
85  /* Implementation note: Explicit template instantiation does not seem
86  to play nice with CRTP, so it was not feasible to factor out the
87  commonality with TcpOptions as a mixin (not without giving up the
88  fluent API). */
89 };
90 
91 //------------------------------------------------------------------------------
94 //------------------------------------------------------------------------------
95 class CPPWAMP_API UdsPath
96 {
97 public:
99  static constexpr RawsockMaxLength defaultMaxRxLength =
101 
103  UdsPath(
104  std::string pathName,
105  UdsOptions options = {},
106  RawsockMaxLength maxRxLength
107  = defaultMaxRxLength
108  );
109 
111  UdsPath& withOptions(UdsOptions options);
112 
114  UdsPath& withMaxRxLength(RawsockMaxLength length);
115 
117  const std::string& pathName() const;
118 
120  const UdsOptions& options() const;
121 
123  RawsockMaxLength maxRxLength() const;
124 
127 
130  CPPWAMP_DEPRECATED UdsPath& withBroadcast(bool enabled = true)
131  {
132  options_.withBroadcast(enabled);
133  return *this;
134  }
135 
137  CPPWAMP_DEPRECATED UdsPath& withDebug(bool enabled = true)
138  {
139  options_.withDebug(enabled);
140  return *this;
141  }
142 
144  CPPWAMP_DEPRECATED UdsPath& withDoNotRoute(bool enabled = true)
145  {
146  options_.withDoNotRoute(enabled);
147  return *this;
148  }
149 
151  CPPWAMP_DEPRECATED UdsPath& withKeepAlive(bool enabled = true)
152  {
153  options_.withKeepAlive(enabled);
154  return *this;
155  }
156 
158  CPPWAMP_DEPRECATED UdsPath& withOutOfBandInline(bool enabled)
159  {
160  options_.withOutOfBandInline(enabled);
161  return *this;
162  }
163 
165  CPPWAMP_DEPRECATED UdsPath& withLinger(bool enabled, int timeout)
166  {
167  options_.withLinger(enabled, timeout);
168  return *this;
169  }
170 
172  CPPWAMP_DEPRECATED UdsPath& withReceiveBufferSize(int size)
173  {
174  options_.withReceiveBufferSize(size);
175  return *this;
176  }
177 
179  CPPWAMP_DEPRECATED UdsPath& withReceiveLowWatermark(int size)
180  {
181  options_.withReceiveLowWatermark(size);
182  return *this;
183  }
184 
186  CPPWAMP_DEPRECATED UdsPath& withReuseAddress(bool enabled = true)
187  {
188  options_.withReuseAddress(enabled);
189  return *this;
190  }
191 
193  CPPWAMP_DEPRECATED UdsPath& withSendBufferSize(int size)
194  {
195  options_.withSendBufferSize(size);
196  return *this;
197  }
198 
200  CPPWAMP_DEPRECATED UdsPath& withSendLowWatermark(int size)
201  {
202  options_.withSendLowWatermark(size);
203  return *this;
204  }
206 
207 private:
208  std::string pathName_;
209  UdsOptions options_;
210  RawsockMaxLength maxRxLength_;
211 };
212 
213 } // namespace wamp
214 
215 #ifndef CPPWAMP_COMPILED_LIB
216 #include "./internal/udspath.ipp"
217 #endif
218 
219 #endif // CPPWAMP_UDSPATH_HPP
wamp::UdsPath::withBroadcast
UdsPath & withBroadcast(bool enabled=true)
The following setters are deprecated.
Definition: udspath.hpp:130
wamp::UdsPath
Contains a Unix domain socket path, as well as other socket options.
Definition: udspath.hpp:95
wamp::RawsockMaxLength::MB_16
@ MB_16
16 megabytes
api.hpp
Defines macros related to exporting/importing APIs.
wamp::UdsPath::withReceiveLowWatermark
UdsPath & withReceiveLowWatermark(int size)
Adds the SO_RCVLOWAT socket option.
Definition: udspath.hpp:179
wamp::UdsPath::withReceiveBufferSize
UdsPath & withReceiveBufferSize(int size)
Adds the SO_RCVBUF socket option.
Definition: udspath.hpp:172
wamp::UdsPath::withReuseAddress
UdsPath & withReuseAddress(bool enabled=true)
Adds the SO_REUSEADDR socket option.
Definition: udspath.hpp:186
wamp
Definition: anyhandler.hpp:36
wamp::UdsPath::withSendLowWatermark
UdsPath & withSendLowWatermark(int size)
Adds the SO_SNDLOWAT socket option.
Definition: udspath.hpp:200
wamp::UdsOptions
Contains options for the UNIX domain socket transport.
Definition: udspath.hpp:39
rawsockoptions.hpp
Contains common option definitions for raw socket transports.
wamp::RawsockMaxLength
RawsockMaxLength
Enumerators used to specify the maximum length of messages that a raw socket transport can receive.
Definition: rawsockoptions.hpp:22
wamp::UdsPath::withLinger
UdsPath & withLinger(bool enabled, int timeout)
Adds the SO_LINGER socket option.
Definition: udspath.hpp:165
wamp::UdsPath::withDebug
UdsPath & withDebug(bool enabled=true)
Adds the SO_DEBUG socket option.
Definition: udspath.hpp:137
wamp::UdsPath::withOutOfBandInline
UdsPath & withOutOfBandInline(bool enabled)
Adds the SO_OOBINLINE socket option.
Definition: udspath.hpp:158
wamp::UdsPath::withSendBufferSize
UdsPath & withSendBufferSize(int size)
Adds the SO_SNDBUF socket option.
Definition: udspath.hpp:193
wamp::UdsPath::withKeepAlive
UdsPath & withKeepAlive(bool enabled=true)
Adds the SO_KEEPALIVE socket option.
Definition: udspath.hpp:151
wamp::UdsPath::withDoNotRoute
UdsPath & withDoNotRoute(bool enabled=true)
Adds the SO_DONTROUTE socket option.
Definition: udspath.hpp:144