Skip to content

Commit d1361d1

Browse files
authored
Allow the transfer of an open socket handle through a AF_UNIX-family ntci::StreamSocket or a ntci::DatagramSocket
1 parent 1eb3b21 commit d1361d1

12 files changed

+860
-105
lines changed

groups/ntc/ntca/ntca_receivecontext.cpp

+52-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ namespace ntca {
2626
bool ReceiveContext::equals(const ReceiveContext& other) const
2727
{
2828
return (d_endpoint == other.d_endpoint &&
29-
d_transport == other.d_transport && d_error == other.d_error);
29+
d_transport == other.d_transport &&
30+
d_compressionType == other.d_compressionType &&
31+
d_compressionRatio == other.d_compressionRatio &&
32+
d_foreignHandle == other.d_foreignHandle &&
33+
d_error == other.d_error);
3034
}
3135

3236
bool ReceiveContext::less(const ReceiveContext& other) const
@@ -47,6 +51,30 @@ bool ReceiveContext::less(const ReceiveContext& other) const
4751
return false;
4852
}
4953

54+
if (d_compressionType < other.d_compressionType) {
55+
return true;
56+
}
57+
58+
if (other.d_compressionType < d_compressionType) {
59+
return false;
60+
}
61+
62+
if (d_compressionRatio < other.d_compressionRatio) {
63+
return true;
64+
}
65+
66+
if (other.d_compressionRatio < d_compressionRatio) {
67+
return false;
68+
}
69+
70+
if (d_foreignHandle < other.d_foreignHandle) {
71+
return true;
72+
}
73+
74+
if (other.d_foreignHandle < d_foreignHandle) {
75+
return false;
76+
}
77+
5078
return d_error < other.d_error;
5179
}
5280

@@ -62,7 +90,29 @@ bsl::ostream& ReceiveContext::print(bsl::ostream& stream,
6290
}
6391

6492
printer.printAttribute("transport", d_transport);
65-
printer.printAttribute("error", d_error);
93+
94+
if (d_compressionType.has_value()) {
95+
printer.printAttribute("compressionType", d_compressionType.value());
96+
}
97+
98+
if (d_compressionRatio.has_value()) {
99+
100+
bsl::ostringstream ss;
101+
ss << bsl::setprecision(2);
102+
ss << bsl::fixed;
103+
ss << d_compressionRatio.value() * 100;
104+
105+
printer.printAttribute("compressionRatio", ss.str());
106+
}
107+
108+
if (d_foreignHandle.has_value()) {
109+
printer.printAttribute("foreignHandle", d_foreignHandle.value());
110+
}
111+
112+
if (d_error) {
113+
printer.printAttribute("error", d_error);
114+
}
115+
66116
printer.end();
67117
return stream;
68118
}

groups/ntc/ntca/ntca_receivecontext.h

+100-7
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919
#include <bsls_ident.h>
2020
BSLS_IDENT("$Id: $")
2121

22+
#include <ntca_compressiontype.h>
2223
#include <ntccfg_platform.h>
2324
#include <ntcscm_version.h>
2425
#include <ntsa_endpoint.h>
2526
#include <ntsa_error.h>
27+
#include <ntsa_handle.h>
2628
#include <ntsa_transport.h>
2729
#include <bdlb_nullablevalue.h>
2830
#include <bslh_hash.h>
@@ -43,6 +45,19 @@ namespace ntca {
4345
/// @li @b transport:
4446
/// The transport the receiver.
4547
///
48+
/// @li @b compressionType:
49+
/// The compression algorithm used to inflate the user's data after reception,
50+
/// if any. If unspecified, no compression was performed.
51+
///
52+
/// @li @b compressionRatio:
53+
/// The ratio of inflated size of the data to the size of the original data
54+
/// actually received. Note that value may be greater than one in the case of
55+
/// poorly-compressible data. If unspecified, no compression was performed.
56+
///
57+
/// @li @b foreignHandle:
58+
/// The foreign handle sent by the peer, if any. If a foreign handle is
59+
/// defined, it is the receivers responsibility to close it.
60+
///
4661
/// @li @b error:
4762
/// The error detected when performing the operation.
4863
///
@@ -52,9 +67,12 @@ namespace ntca {
5267
/// @ingroup module_ntci_operation_receive
5368
class ReceiveContext
5469
{
55-
bdlb::NullableValue<ntsa::Endpoint> d_endpoint;
56-
ntsa::Transport::Value d_transport;
57-
ntsa::Error d_error;
70+
bdlb::NullableValue<ntsa::Endpoint> d_endpoint;
71+
ntsa::Transport::Value d_transport;
72+
bdlb::NullableValue<ntca::CompressionType::Value> d_compressionType;
73+
bdlb::NullableValue<double> d_compressionRatio;
74+
bdlb::NullableValue<ntsa::Handle> d_foreignHandle;
75+
ntsa::Error d_error;
5876

5977
public:
6078
/// Create a new receive context having the default value.
@@ -82,6 +100,17 @@ class ReceiveContext
82100
/// Set the transport of the receiver to the specified 'value'.
83101
void setTransport(ntsa::Transport::Value value);
84102

103+
/// Set the compression algorithm used to inflate the user's data after
104+
/// reception to the specified 'value'.
105+
void setCompressionType(ntca::CompressionType::Value value);
106+
107+
/// Set the ratio of inflated size of the data to the size of the original
108+
/// data actually received to the specified 'value'.
109+
void setCompressionRatio(double value);
110+
111+
/// Set the foreign handle sent by the peer to the specified 'value'.
112+
void setForeignHandle(ntsa::Handle value);
113+
85114
/// Set the error detected when performing the operation to the
86115
/// specified 'value'.
87116
void setError(const ntsa::Error& value);
@@ -108,6 +137,18 @@ class ReceiveContext
108137
/// the transport of the receiver.
109138
ntsa::TransportProtocol::Value transportProtocol() const;
110139

140+
/// Return the compression algorithm used to inflate the user's data after
141+
/// reception.
142+
const bdlb::NullableValue<ntca::CompressionType::Value>&
143+
compressionType() const;
144+
145+
/// Return the ratio of inflated size of the data to the size of the
146+
/// original data actually received.
147+
const bdlb::NullableValue<double>& compressionRatio() const;
148+
149+
/// Return the foreign handle sent by the peer, if any.
150+
const bdlb::NullableValue<ntsa::Handle>& foreignHandle() const;
151+
111152
/// Return the error detected when performing the operation.
112153
const ntsa::Error& error() const;
113154

@@ -180,6 +221,9 @@ NTCCFG_INLINE
180221
ReceiveContext::ReceiveContext()
181222
: d_endpoint()
182223
, d_transport(ntsa::Transport::e_UNDEFINED)
224+
, d_compressionType()
225+
, d_compressionRatio()
226+
, d_foreignHandle()
183227
, d_error()
184228
{
185229
}
@@ -188,6 +232,9 @@ NTCCFG_INLINE
188232
ReceiveContext::ReceiveContext(const ReceiveContext& original)
189233
: d_endpoint(original.d_endpoint)
190234
, d_transport(original.d_transport)
235+
, d_compressionType(original.d_compressionType)
236+
, d_compressionRatio(original.d_compressionRatio)
237+
, d_foreignHandle(original.d_foreignHandle)
191238
, d_error(original.d_error)
192239
{
193240
}
@@ -200,9 +247,12 @@ ReceiveContext::~ReceiveContext()
200247
NTCCFG_INLINE
201248
ReceiveContext& ReceiveContext::operator=(const ReceiveContext& other)
202249
{
203-
d_endpoint = other.d_endpoint;
204-
d_transport = other.d_transport;
205-
d_error = other.d_error;
250+
d_endpoint = other.d_endpoint;
251+
d_transport = other.d_transport;
252+
d_compressionType = other.d_compressionType;
253+
d_compressionRatio = other.d_compressionRatio;
254+
d_foreignHandle = other.d_foreignHandle;
255+
d_error = other.d_error;
206256
return *this;
207257
}
208258

@@ -211,7 +261,10 @@ void ReceiveContext::reset()
211261
{
212262
d_endpoint.reset();
213263
d_transport = ntsa::Transport::e_UNDEFINED;
214-
d_error = ntsa::Error();
264+
d_compressionType.reset();
265+
d_compressionRatio.reset();
266+
d_foreignHandle.reset();
267+
d_error = ntsa::Error();
215268
}
216269

217270
NTCCFG_INLINE
@@ -226,6 +279,24 @@ void ReceiveContext::setTransport(ntsa::Transport::Value value)
226279
d_transport = value;
227280
}
228281

282+
NTCCFG_INLINE
283+
void ReceiveContext::setCompressionType(ntca::CompressionType::Value value)
284+
{
285+
d_compressionType = value;
286+
}
287+
288+
NTCCFG_INLINE
289+
void ReceiveContext::setCompressionRatio(double value)
290+
{
291+
d_compressionRatio = value;
292+
}
293+
294+
NTCCFG_INLINE
295+
void ReceiveContext::setForeignHandle(ntsa::Handle value)
296+
{
297+
d_foreignHandle = value;
298+
}
299+
229300
NTCCFG_INLINE
230301
void ReceiveContext::setError(const ntsa::Error& value)
231302
{
@@ -262,6 +333,25 @@ ntsa::TransportProtocol::Value ReceiveContext::transportProtocol() const
262333
return ntsa::Transport::getProtocol(d_transport);
263334
}
264335

336+
NTCCFG_INLINE
337+
const bdlb::NullableValue<ntca::CompressionType::Value>&
338+
ReceiveContext::compressionType() const
339+
{
340+
return d_compressionType;
341+
}
342+
343+
NTCCFG_INLINE
344+
const bdlb::NullableValue<double>& ReceiveContext::compressionRatio() const
345+
{
346+
return d_compressionRatio;
347+
}
348+
349+
NTCCFG_INLINE
350+
const bdlb::NullableValue<ntsa::Handle>& ReceiveContext::foreignHandle() const
351+
{
352+
return d_foreignHandle;
353+
}
354+
265355
NTCCFG_INLINE
266356
const ntsa::Error& ReceiveContext::error() const
267357
{
@@ -299,6 +389,9 @@ void hashAppend(HASH_ALGORITHM& algorithm, const ReceiveContext& value)
299389

300390
hashAppend(algorithm, value.endpoint());
301391
hashAppend(algorithm, value.transport());
392+
hashAppend(algorithm, value.compressionType());
393+
hashAppend(algorithm, value.compressionRatio());
394+
hashAppend(algorithm, value.foreignHandle());
302395
hashAppend(algorithm, value.error());
303396
}
304397

groups/ntc/ntca/ntca_sendoptions.cpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ bool SendOptions::equals(const SendOptions& other) const
2828
return (d_token == other.d_token && d_endpoint == other.d_endpoint &&
2929
d_priority == other.d_priority &&
3030
d_highWatermark == other.d_highWatermark &&
31-
d_deadline == other.d_deadline && d_recurse == other.d_recurse);
31+
d_deadline == other.d_deadline &&
32+
d_foreignHandle == other.d_foreignHandle &&
33+
d_recurse == other.d_recurse);
3234
}
3335

3436
bool SendOptions::less(const SendOptions& other) const
@@ -73,6 +75,14 @@ bool SendOptions::less(const SendOptions& other) const
7375
return false;
7476
}
7577

78+
if (d_foreignHandle < other.d_foreignHandle) {
79+
return true;
80+
}
81+
82+
if (other.d_foreignHandle < d_foreignHandle) {
83+
return false;
84+
}
85+
7686
return d_recurse < other.d_recurse;
7787
}
7888

@@ -103,6 +113,10 @@ bsl::ostream& SendOptions::print(bsl::ostream& stream,
103113
printer.printAttribute("deadline", d_deadline);
104114
}
105115

116+
if (!d_deadline.isNull()) {
117+
printer.printAttribute("foreignHandle", d_foreignHandle);
118+
}
119+
106120
printer.printAttribute("recurse", d_recurse);
107121
printer.end();
108122
return stream;

0 commit comments

Comments
 (0)