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