1nbd_aio_get_direction(3)            LIBNBD            nbd_aio_get_direction(3)
2
3
4

NAME

6       nbd_aio_get_direction - return the read or write direction
7

SYNOPSIS

9        #include <libnbd.h>
10
11        unsigned nbd_aio_get_direction (struct nbd_handle *h);
12

DESCRIPTION

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

RETURN VALUE

55       This call returns a bitmask.
56

ERRORS

58       This function does not fail.
59
60       The following parameters must not be NULL: "h".  For more information
61       see "Non-NULL parameters" in libnbd(3).
62

VERSION

64       This function first appeared in libnbd 1.0.
65
66       If you need to test if this function is available at compile time check
67       if the following macro is defined:
68
69        #define LIBNBD_HAVE_NBD_AIO_GET_DIRECTION 1
70

SEE ALSO

72       nbd_aio_connect(3), nbd_aio_in_flight(3), nbd_aio_is_ready(3),
73       nbd_aio_notify_read(3), nbd_aio_notify_write(3), nbd_create(3),
74       libnbd(3), poll(2), ppoll(2), pthread_kill(3).
75

AUTHORS

77       Eric Blake
78
79       Richard W.M. Jones
80
82       Copyright (C) 2019-2021 Red Hat Inc.
83

LICENSE

85       This library is free software; you can redistribute it and/or modify it
86       under the terms of the GNU Lesser General Public License as published
87       by the Free Software Foundation; either version 2 of the License, or
88       (at your option) any later version.
89
90       This library is distributed in the hope that it will be useful, but
91       WITHOUT ANY WARRANTY; without even the implied warranty of
92       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
93       Lesser General Public License for more details.
94
95       You should have received a copy of the GNU Lesser General Public
96       License along with this library; if not, write to the Free Software
97       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
98       02110-1301 USA
99
100
101
102libnbd-1.14.2                     2023-01-03          nbd_aio_get_direction(3)
Impressum