1nbd_aio_get_direction(3) LIBNBD nbd_aio_get_direction(3)
2
3
4
6 nbd_aio_get_direction - return the read or write direction
7
9 #include <libnbd.h>
10
11 unsigned nbd_aio_get_direction (struct nbd_handle *h);
12
14 Return the current direction of this connection, which means whether we
15 are next expecting to read data from the server, write data to the
16 server, or both. It returns
17
18 0 We are not expected to interact with the server file descriptor
19 from the current state. It is not worth attempting to use poll(2);
20 if the connection is not dead, then state machine progress must
21 instead come from some other means such as nbd_aio_connect(3).
22
23 "LIBNBD_AIO_DIRECTION_READ" = 1
24 We are expected next to read from the server. If using poll(2) you
25 would set "events = POLLIN". If "revents" returns "POLLIN" or
26 "POLLHUP" you would then call nbd_aio_notify_read(3).
27
28 Note that once libnbd reaches nbd_aio_is_ready(3), this direction
29 is returned even when there are no commands in flight (see
30 nbd_aio_in_flight(3)). In a single-threaded use of libnbd, it is
31 not worth polling until after issuing a command, as otherwise the
32 server will never wake up the poll. In a multi-threaded scenario,
33 you can have one thread begin a polling loop prior to any commands,
34 but any other thread that issues a command will need a way to kick
35 the polling thread out of poll in case issuing the command changes
36 the needed polling direction. Possible ways to do this include
37 polling for activity on a pipe-to-self, or using pthread_kill(3) to
38 send a signal that is masked except during ppoll(2).
39
40 "LIBNBD_AIO_DIRECTION_WRITE" = 2
41 We are expected next to write to the server. If using poll(2) you
42 would set "events = POLLOUT". If "revents" returns "POLLOUT" you
43 would then call nbd_aio_notify_write(3).
44
45 "LIBNBD_AIO_DIRECTION_BOTH" = 3
46 We are expected next to either read or write to the server. If
47 using poll(2) you would set "events = POLLIN|POLLOUT". If only one
48 of "POLLIN" or "POLLOUT" is returned, then see above. However, if
49 both are returned, it is better to call only
50 nbd_aio_notify_read(3), as processing the server's reply may change
51 the state of the connection and invalidate the need to write more
52 commands.
53
55 This call returns a bitmask.
56
58 This function does not fail.
59
61 This function first appeared in libnbd 1.0.
62
63 If you need to test if this function is available at compile time check
64 if the following macro is defined:
65
66 #define LIBNBD_HAVE_NBD_AIO_GET_DIRECTION 1
67
69 nbd_aio_connect(3), nbd_aio_in_flight(3), nbd_aio_is_ready(3),
70 nbd_aio_notify_read(3), nbd_aio_notify_write(3), nbd_create(3),
71 libnbd(3), poll(2), ppoll(2), pthread_kill(3).
72
74 Eric Blake
75
76 Richard W.M. Jones
77
79 Copyright (C) 2019-2021 Red Hat Inc.
80
82 This library is free software; you can redistribute it and/or modify it
83 under the terms of the GNU Lesser General Public License as published
84 by the Free Software Foundation; either version 2 of the License, or
85 (at your option) any later version.
86
87 This library is distributed in the hope that it will be useful, but
88 WITHOUT ANY WARRANTY; without even the implied warranty of
89 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
90 Lesser General Public License for more details.
91
92 You should have received a copy of the GNU Lesser General Public
93 License along with this library; if not, write to the Free Software
94 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
95 02110-1301 USA
96
97
98
99libnbd-1.12.5 2022-07-10 nbd_aio_get_direction(3)