TLA Line data Source code
1 : //
2 : // Copyright (c) 2026 Michael Vandeberg
3 : //
4 : // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 : // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 : //
7 : // Official repository: https://github.com/cppalliance/corosio
8 : //
9 :
10 : #ifndef BOOST_COROSIO_NATIVE_DETAIL_REACTOR_REACTOR_DESCRIPTOR_OPS_HPP
11 : #define BOOST_COROSIO_NATIVE_DETAIL_REACTOR_REACTOR_DESCRIPTOR_OPS_HPP
12 :
13 : #include <boost/corosio/detail/platform.hpp>
14 :
15 : #if BOOST_COROSIO_POSIX
16 :
17 : #include <cstddef>
18 :
19 : #include <errno.h>
20 : #include <sys/types.h>
21 : #include <sys/uio.h>
22 : #include <unistd.h>
23 :
24 : namespace boost::corosio::detail {
25 :
26 : /* Write policy shared by every reactor backend's descriptor ops.
27 :
28 : Descriptors are not sockets: sendmsg() fails with ENOTSOCK on a pipe
29 : or character device, so the write path is writev()/write() and
30 : SIGPIPE suppression is structurally unavailable -- MSG_NOSIGNAL is a
31 : send() flag and SO_NOSIGPIPE a socket option. A write to a pipe whose
32 : read end has closed raises SIGPIPE, exactly as a plain write(2)
33 : would; callers install SIG_IGN.
34 : */
35 : struct descriptor_write_policy
36 : {
37 HIT 4 : static ssize_t write(int fd, iovec* iovecs, int count) noexcept
38 : {
39 : ssize_t n;
40 : do
41 : {
42 4 : n = ::writev(fd, iovecs, count);
43 : }
44 4 : while (n < 0 && errno == EINTR);
45 4 : return n;
46 : }
47 :
48 : // Single-buffer fast path: skips the kernel's iov_iter setup.
49 : static ssize_t
50 18 : write_one(int fd, void const* data, std::size_t size) noexcept
51 : {
52 : ssize_t n;
53 : do
54 : {
55 18 : n = ::write(fd, data, size);
56 : }
57 18 : while (n < 0 && errno == EINTR);
58 18 : return n;
59 : }
60 : };
61 :
62 : } // namespace boost::corosio::detail
63 :
64 : #endif // BOOST_COROSIO_POSIX
65 :
66 : #endif // BOOST_COROSIO_NATIVE_DETAIL_REACTOR_REACTOR_DESCRIPTOR_OPS_HPP
|