Flow-IPC 1.0.0
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 #error that this is being built in POSIX. (Windows has a special value too though.)
29
30// Native_handle implementations.
31
33 m_native_handle(native_handle)
34{
35 // Nope.
36}
37
39{
40 // It's why we exist: prevent duplication of src.m_native_handle.
41 operator=(std::move(src));
42}
43
45
47{
48 using std::swap;
49
50 if (*this != src)
51 {
53 swap(m_native_handle, src.m_native_handle); // No-op if `&src == this`.
54 }
55 return *this;
56}
57
59
61{
63}
64
65std::ostream& operator<<(std::ostream& os, const Native_handle& val)
66{
67 os << "native_hndl[";
68 if (val.null())
69 {
70 os << "NONE";
71 }
72 else
73 {
74 os << val.m_native_handle;
75 }
76 return os << ']';
77}
78
80{
81 return val1.m_native_handle == val2.m_native_handle;
82}
83
85{
86 return !operator==(val1, val2);
87}
88
90{
91 using boost::hash;
92
93 return hash<Native_handle::handle_t>()(val.m_native_handle);
94}
95
97{
98 /* In POSIX and Windows this is valid. So don't worry about #ifdef'ing for OS, #error, etc.
99 * I did check that even in Windows they are formally integers still. */
100 return val1.m_native_handle < val2.m_native_handle;
101}
102
103} // 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.