xref: /openbmc/qemu/include/io/channel-util.h (revision 06e0f098)
1c767ae62SDaniel P. Berrange /*
2c767ae62SDaniel P. Berrange  * QEMU I/O channels utility APIs
3c767ae62SDaniel P. Berrange  *
4c767ae62SDaniel P. Berrange  * Copyright (c) 2016 Red Hat, Inc.
5c767ae62SDaniel P. Berrange  *
6c767ae62SDaniel P. Berrange  * This library is free software; you can redistribute it and/or
7c767ae62SDaniel P. Berrange  * modify it under the terms of the GNU Lesser General Public
8c767ae62SDaniel P. Berrange  * License as published by the Free Software Foundation; either
9c8198bd5SChetan Pant  * version 2.1 of the License, or (at your option) any later version.
10c767ae62SDaniel P. Berrange  *
11c767ae62SDaniel P. Berrange  * This library is distributed in the hope that it will be useful,
12c767ae62SDaniel P. Berrange  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13c767ae62SDaniel P. Berrange  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14c767ae62SDaniel P. Berrange  * Lesser General Public License for more details.
15c767ae62SDaniel P. Berrange  *
16c767ae62SDaniel P. Berrange  * You should have received a copy of the GNU Lesser General Public
17c767ae62SDaniel P. Berrange  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18c767ae62SDaniel P. Berrange  *
19c767ae62SDaniel P. Berrange  */
20c767ae62SDaniel P. Berrange 
212a6a4076SMarkus Armbruster #ifndef QIO_CHANNEL_UTIL_H
222a6a4076SMarkus Armbruster #define QIO_CHANNEL_UTIL_H
23c767ae62SDaniel P. Berrange 
24c767ae62SDaniel P. Berrange #include "io/channel.h"
25c767ae62SDaniel P. Berrange 
26c767ae62SDaniel P. Berrange /*
27c767ae62SDaniel P. Berrange  * This module provides helper functions that are useful when dealing
28c767ae62SDaniel P. Berrange  * with QIOChannel objects
29c767ae62SDaniel P. Berrange  */
30c767ae62SDaniel P. Berrange 
31c767ae62SDaniel P. Berrange 
32c767ae62SDaniel P. Berrange /**
33c767ae62SDaniel P. Berrange  * qio_channel_new_fd:
34c767ae62SDaniel P. Berrange  * @fd: the file descriptor
35c767ae62SDaniel P. Berrange  * @errp: pointer to a NULL-initialized error object
36c767ae62SDaniel P. Berrange  *
37c767ae62SDaniel P. Berrange  * Create a channel for performing I/O on the file
38c767ae62SDaniel P. Berrange  * descriptor @fd. The particular subclass of QIOChannel
39c767ae62SDaniel P. Berrange  * that is returned will depend on what underlying object
40c767ae62SDaniel P. Berrange  * the file descriptor is associated with. It may be either
41c767ae62SDaniel P. Berrange  * a QIOChannelSocket or a QIOChannelFile instance. Upon
42c767ae62SDaniel P. Berrange  * success, the returned QIOChannel instance will own
43c767ae62SDaniel P. Berrange  * the @fd file descriptor, and take responsibility for
44c767ae62SDaniel P. Berrange  * closing it when no longer required. On failure, the
45c767ae62SDaniel P. Berrange  * caller is responsible for closing @fd.
46c767ae62SDaniel P. Berrange  *
47c767ae62SDaniel P. Berrange  * Returns: the channel object, or NULL on error
48c767ae62SDaniel P. Berrange  */
49c767ae62SDaniel P. Berrange QIOChannel *qio_channel_new_fd(int fd,
50c767ae62SDaniel P. Berrange                                Error **errp);
51c767ae62SDaniel P. Berrange 
52*06e0f098SStefan Hajnoczi /**
53*06e0f098SStefan Hajnoczi  * qio_channel_util_set_aio_fd_handler:
54*06e0f098SStefan Hajnoczi  * @read_fd: the file descriptor for the read handler
55*06e0f098SStefan Hajnoczi  * @read_ctx: the AioContext for the read handler
56*06e0f098SStefan Hajnoczi  * @io_read: the read handler
57*06e0f098SStefan Hajnoczi  * @write_fd: the file descriptor for the write handler
58*06e0f098SStefan Hajnoczi  * @write_ctx: the AioContext for the write handler
59*06e0f098SStefan Hajnoczi  * @io_write: the write handler
60*06e0f098SStefan Hajnoczi  * @opaque: the opaque argument to the read and write handler
61*06e0f098SStefan Hajnoczi  *
62*06e0f098SStefan Hajnoczi  * Set the read and write handlers when @read_ctx and @write_ctx are non-NULL,
63*06e0f098SStefan Hajnoczi  * respectively. To leave a handler in its current state, pass a NULL
64*06e0f098SStefan Hajnoczi  * AioContext. To clear a handler, pass a non-NULL AioContext and a NULL
65*06e0f098SStefan Hajnoczi  * handler.
66*06e0f098SStefan Hajnoczi  */
67*06e0f098SStefan Hajnoczi void qio_channel_util_set_aio_fd_handler(int read_fd,
68*06e0f098SStefan Hajnoczi                                          AioContext *read_ctx,
69*06e0f098SStefan Hajnoczi                                          IOHandler *io_read,
70*06e0f098SStefan Hajnoczi                                          int write_fd,
71*06e0f098SStefan Hajnoczi                                          AioContext *write_ctx,
72*06e0f098SStefan Hajnoczi                                          IOHandler *io_write,
73*06e0f098SStefan Hajnoczi                                          void *opaque);
74*06e0f098SStefan Hajnoczi 
752a6a4076SMarkus Armbruster #endif /* QIO_CHANNEL_UTIL_H */
76