Flow-IPC 1.0.1
Flow-IPC project: Full implementation reference.
asio_waitable_native_hndl.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 "ipc/common.hpp"
21
22namespace ipc::util::sync_io
23{
24
25// Implementations.
26
28 Base(ex, hndl.m_native_handle)
29{
30 /* This might be too late; I do know that ->assign() throws "Bad descriptor" in Linux on .null() (-1) handle.
31 * It (assign()), as of Boost-1.81 anyway, immediately does an epoll_ctl(ADD) on it which yields bad-descriptor
32 * error. */
33 assert(!hndl.null());
34}
35
37 Base(ex)
38{
39 // Yeah.
40}
41
43
45
47{
48 /* boost.asio documentation is slightly ambiguous -- well, terse as usual -- as to whether `Base::~Base()`
49 * (posix::basic_descriptor dtor), which is `protected` by the way, will act as-if .close() was called,
50 * in the way that certainly (e.g.) ipc::tcp::socket::~socket() does. Of course we could test it; but
51 * various signs and common sense indicate that it would in fact ::close() the FD. Even if not, the following
52 * would do no harm though. To be clear: We do *not* want to close it. We exist for watchability only. */
53 release();
54
55 // Probably any async_wait() would get operation_aborted because of that. They should be ready for that anyway.
56
57 // Now Base::~Base() will do its usual thing, but on a (perfectly valid) as-if-default-cted *this.
58}
59
61{
62 return Base::is_open()? Native_handle(Base::native_handle()) : Native_handle();
63}
64
66{
67 assert(!hndl.null()); // See comment in 2+-arg ctor above.
68
69 if (is_open())
70 {
71 release();
72 }
73
74 Error_code err_code_ok;
75 Base::assign(hndl.m_native_handle, err_code_ok);
76
77 if (err_code_ok)
78 {
79 assert(false && "This can fail at least with bad-descriptor error in Linux; but if you followed "
80 "contract (passed valid descriptor), then it will not. Bug? Blowing up.");
81 std::abort();
82 }
83}
84
85} // namespace ipc::util::sync_io
Useful if using the sync_io pattern within a user event loop built on boost.asio (optionally with flo...
~Asio_waitable_native_handle()
Destructor that does not OS-close ("::close()") the stored native handle (if any) but rather performs...
Asio_waitable_native_handle(const Base::executor_type &ex, Native_handle hndl)
Construct boost.asio descriptor object such that one can async_wait() events on the given non-....
boost::asio::posix::descriptor Base
Short-hand for our base type; can be used for, e.g., Base::wait_write and Base::wait_read.
void assign(Native_handle hndl)
Loads value to be returned by native_handle().
Native_handle native_handle()
Returns the same Native_handle as passed to original handle-loading ctor or assign(),...
Asio_waitable_native_handle & operator=(Asio_waitable_native_handle &&src)
Move-assign.
util::Native_handle Native_handle
Convenience alias for the commonly used type util::Native_handle.
Contains common code, as well as important explanatory documentation in the following text,...
Definition: util_fwd.hpp:208
flow::Error_code Error_code
Short-hand for flow::Error_code which is very common.
Definition: common.hpp:297
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.
handle_t m_native_handle
The native handle (possibly equal to S_NULL_HANDLE), the exact payload of this Native_handle.