tests: Raise timeouts for bufferiszero and crypto-tlscredsx509
[qemu/kevin.git] / io / channel-null.c
blobef995863483cc6f7eb30bdaea15b95d6514df0f3
1 /*
2 * QEMU I/O channels null driver
4 * Copyright (c) 2022 Red Hat, Inc.
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.
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.
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/>.
21 #include "qemu/osdep.h"
22 #include "io/channel-null.h"
23 #include "io/channel-watch.h"
24 #include "qapi/error.h"
25 #include "trace.h"
26 #include "qemu/iov.h"
28 typedef struct QIOChannelNullSource QIOChannelNullSource;
29 struct QIOChannelNullSource {
30 GSource parent;
31 QIOChannel *ioc;
32 GIOCondition condition;
36 QIOChannelNull *
37 qio_channel_null_new(void)
39 QIOChannelNull *ioc;
41 ioc = QIO_CHANNEL_NULL(object_new(TYPE_QIO_CHANNEL_NULL));
43 trace_qio_channel_null_new(ioc);
45 return ioc;
49 static void
50 qio_channel_null_init(Object *obj)
52 QIOChannelNull *ioc = QIO_CHANNEL_NULL(obj);
53 ioc->closed = false;
57 static ssize_t
58 qio_channel_null_readv(QIOChannel *ioc,
59 const struct iovec *iov,
60 size_t niov,
61 int **fds G_GNUC_UNUSED,
62 size_t *nfds G_GNUC_UNUSED,
63 int flags,
64 Error **errp)
66 QIOChannelNull *nioc = QIO_CHANNEL_NULL(ioc);
68 if (nioc->closed) {
69 error_setg_errno(errp, EINVAL,
70 "Channel is closed");
71 return -1;
74 return 0;
78 static ssize_t
79 qio_channel_null_writev(QIOChannel *ioc,
80 const struct iovec *iov,
81 size_t niov,
82 int *fds G_GNUC_UNUSED,
83 size_t nfds G_GNUC_UNUSED,
84 int flags G_GNUC_UNUSED,
85 Error **errp)
87 QIOChannelNull *nioc = QIO_CHANNEL_NULL(ioc);
89 if (nioc->closed) {
90 error_setg_errno(errp, EINVAL,
91 "Channel is closed");
92 return -1;
95 return iov_size(iov, niov);
99 static int
100 qio_channel_null_set_blocking(QIOChannel *ioc G_GNUC_UNUSED,
101 bool enabled G_GNUC_UNUSED,
102 Error **errp G_GNUC_UNUSED)
104 return 0;
108 static off_t
109 qio_channel_null_seek(QIOChannel *ioc G_GNUC_UNUSED,
110 off_t offset G_GNUC_UNUSED,
111 int whence G_GNUC_UNUSED,
112 Error **errp G_GNUC_UNUSED)
114 return 0;
118 static int
119 qio_channel_null_close(QIOChannel *ioc,
120 Error **errp G_GNUC_UNUSED)
122 QIOChannelNull *nioc = QIO_CHANNEL_NULL(ioc);
124 nioc->closed = true;
125 return 0;
129 static void
130 qio_channel_null_set_aio_fd_handler(QIOChannel *ioc G_GNUC_UNUSED,
131 AioContext *read_ctx G_GNUC_UNUSED,
132 IOHandler *io_read G_GNUC_UNUSED,
133 AioContext *write_ctx G_GNUC_UNUSED,
134 IOHandler *io_write G_GNUC_UNUSED,
135 void *opaque G_GNUC_UNUSED)
140 static gboolean
141 qio_channel_null_source_prepare(GSource *source G_GNUC_UNUSED,
142 gint *timeout)
144 *timeout = -1;
146 return TRUE;
150 static gboolean
151 qio_channel_null_source_check(GSource *source G_GNUC_UNUSED)
153 return TRUE;
157 static gboolean
158 qio_channel_null_source_dispatch(GSource *source,
159 GSourceFunc callback,
160 gpointer user_data)
162 QIOChannelFunc func = (QIOChannelFunc)callback;
163 QIOChannelNullSource *ssource = (QIOChannelNullSource *)source;
165 return (*func)(ssource->ioc,
166 ssource->condition,
167 user_data);
171 static void
172 qio_channel_null_source_finalize(GSource *source)
174 QIOChannelNullSource *ssource = (QIOChannelNullSource *)source;
176 object_unref(OBJECT(ssource->ioc));
180 GSourceFuncs qio_channel_null_source_funcs = {
181 qio_channel_null_source_prepare,
182 qio_channel_null_source_check,
183 qio_channel_null_source_dispatch,
184 qio_channel_null_source_finalize
188 static GSource *
189 qio_channel_null_create_watch(QIOChannel *ioc,
190 GIOCondition condition)
192 GSource *source;
193 QIOChannelNullSource *ssource;
195 source = g_source_new(&qio_channel_null_source_funcs,
196 sizeof(QIOChannelNullSource));
197 ssource = (QIOChannelNullSource *)source;
199 ssource->ioc = ioc;
200 object_ref(OBJECT(ioc));
202 ssource->condition = condition;
204 return source;
208 static void
209 qio_channel_null_class_init(ObjectClass *klass,
210 void *class_data G_GNUC_UNUSED)
212 QIOChannelClass *ioc_klass = QIO_CHANNEL_CLASS(klass);
214 ioc_klass->io_writev = qio_channel_null_writev;
215 ioc_klass->io_readv = qio_channel_null_readv;
216 ioc_klass->io_set_blocking = qio_channel_null_set_blocking;
217 ioc_klass->io_seek = qio_channel_null_seek;
218 ioc_klass->io_close = qio_channel_null_close;
219 ioc_klass->io_create_watch = qio_channel_null_create_watch;
220 ioc_klass->io_set_aio_fd_handler = qio_channel_null_set_aio_fd_handler;
224 static const TypeInfo qio_channel_null_info = {
225 .parent = TYPE_QIO_CHANNEL,
226 .name = TYPE_QIO_CHANNEL_NULL,
227 .instance_size = sizeof(QIOChannelNull),
228 .instance_init = qio_channel_null_init,
229 .class_init = qio_channel_null_class_init,
233 static void
234 qio_channel_null_register_types(void)
236 type_register_static(&qio_channel_null_info);
239 type_init(qio_channel_null_register_types);