Flow-IPC 1.0.2
Flow-IPC project: Full implementation reference.
native_handle.cpp
Go to the documentation of this file.
1/* Flow-IPC: Core
2 * Copyright 2023 Akamai Technologies, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the
5 * "License"); you may not use this file except in
6 * compliance with the License. You may obtain a copy
7 * of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in
12 * writing, software distributed under the License is
13 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14 * CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing
16 * permissions and limitations under the License. */
17
18/// @file
20#include <boost/functional/hash/hash.hpp>
21
22namespace ipc::util
23{
24
25// Static initializers.
26
27/* Reminder: We've assured via static_assert(false) that this is being built in POSIX.
28 * (Windows has a special value too though.) */
30
31// Native_handle implementations.
32
34 m_native_handle(native_handle)
35{
36 // Nope.
37}
38
40{
41 // It's why we exist: prevent duplication of src.m_native_handle.
42 operator=(std::move(src));
43}
44
46
48{
49 using std::swap;
50
51 if (*this != src)
52 {
54 swap(m_native_handle, src.m_native_handle); // No-op if `&src == this`.
55 }
56 return *this;
57}
58
60
62{
64}
65
66std::ostream& operator<<(std::ostream& os, const Native_handle& val)
67{
68 os << "native_hndl[";
69 if (val.null())
70 {
71 os << "NONE";
72 }
73 else
74 {
75 os << val.m_native_handle;
76 }
77 return os << ']';
78}
79
81{
82 return val1.m_native_handle == val2.m_native_handle;
83}
84
86{
87 return !operator==(val1, val2);
88}
89
91{
92 using boost::hash;
93
94 return hash<Native_handle::handle_t>()(val.m_native_handle);
95}
96
98{
99 /* In POSIX and Windows this is valid. So don't worry about #ifdef'ing for OS, static_assert(false), etc.
100 * I did check that even in Windows they are formally integers still. Update: Actually... not sure... depends
101 * on what's a Native_handle; if it's SOCKET then sure, but otherwise -- who knows? There's probably a ticket
102 * about that whole topic. */
103 return val1.m_native_handle < val2.m_native_handle;
104}
105
106} // namespace ipc::util
void swap(Bipc_mq_handle &val1, Bipc_mq_handle &val2)
Implements Persistent_mq_handle related concept: Swaps two objects.
Flow-IPC module containing miscellaneous general-use facilities that ubiquitously used by ~all Flow-I...
std::ostream & operator<<(std::ostream &os, const Native_handle &val)
Prints string representation of the given Native_handle to the given ostream.
bool operator<(Native_handle val1, Native_handle val2)
Returns a less-than comparison of two Native_handle objects, with the usual total ordering guarantees...
void swap(Shared_name &val1, Shared_name &val2)
Swaps two objects.
bool operator!=(Native_handle val1, Native_handle val2)
Negation of similar ==.
size_t hash_value(Native_handle val)
Hasher of Native_handle for boost.unordered et al.
bool operator==(Native_handle val1, Native_handle val2)
Returns true if and only if the two Native_handle objects are the same underlying handle.
A monolayer-thin wrapper around a native handle, a/k/a descriptor a/k/a FD.
bool null() const
Returns true if and only if m_native_handle equals S_NULL_HANDLE.
Native_handle(handle_t native_handle=S_NULL_HANDLE)
Constructs with given payload; also subsumes no-args construction to mean constructing an object with...
static const handle_t S_NULL_HANDLE
The value for m_native_handle such that null() == true; else it is false.
Native_handle & operator=(Native_handle &&src)
Move assignment; acts similarly to move ctor; but no-op if *this == src.
int handle_t
The native handle type. Much logic relies on this type being light-weight (fast to copy).
handle_t m_native_handle
The native handle (possibly equal to S_NULL_HANDLE), the exact payload of this Native_handle.