José: /home/nmccallu/Projects/jose/jose/io.h Source File

José

io.h
1 /* vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80: */
2 /*
3 * Copyright 2017 Red Hat, Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
24 #pragma once
25
26 #include "cfg.h"
27 #include <stdbool.h>
28 #include <stdio.h>
29
30 #ifdef DOXYGEN
31
43 typedef jose_io_t jose_io_auto_t;
44
61 typedef struct {
70 bool (*feed)(jose_io_t *io, const void *in, size_t len);
71
80 bool (*done)(jose_io_t *io);
81 } jose_io_t;
82 #else
83 #define jose_io_auto_t jose_io_t __attribute__((cleanup(jose_io_auto)))
84
85 typedef struct jose_io jose_io_t;
86 struct jose_io {
87 size_t refs;
88 bool (*feed)(jose_io_t *io, const void *in, size_t len);
89 bool (*done)(jose_io_t *io);
90 void (*free)(jose_io_t *io); /* Don't call this. Use jose_io_decref(). */
91 };
92 #endif
93
94 void
95 jose_io_auto(jose_io_t **io);
96
105 jose_io_t *
106 jose_io_incref(jose_io_t *io);
107
115 void
116 jose_io_decref(jose_io_t *io);
117
136 jose_io_t *
137 jose_io_malloc(jose_cfg_t *cfg, void **buf, size_t *len);
138
149 void *
150 jose_io_malloc_steal(void **buf);
151
168 jose_io_t *
169 jose_io_buffer(jose_cfg_t *cfg, void *buf, size_t *len);
170
181 jose_io_t *
182 jose_io_file(jose_cfg_t *cfg, FILE *file);
183
195 jose_io_t *
196 jose_io_multiplex(jose_cfg_t *cfg, jose_io_t **nexts, bool all);
197
jose_io_incref
jose_io_t * jose_io_incref(jose_io_t *io)
Increases the reference count of an IO object.
jose_io_malloc
jose_io_t * jose_io_malloc(jose_cfg_t *cfg, void **buf, size_t *len)
Creates a new IO object which collects data into a dynamic buffer.
jose_io_decref
void jose_io_decref(jose_io_t *io)
Decreases the reference count of an IO object.
jose_io_file
jose_io_t * jose_io_file(jose_cfg_t *cfg, FILE *file)
Creates a new IO object which writes data into a FILE.
jose_io_multiplex
jose_io_t * jose_io_multiplex(jose_cfg_t *cfg, jose_io_t **nexts, bool all)
Creates a new IO object which multiplexes data into multiple IO objects.
jose_io_buffer
jose_io_t * jose_io_buffer(jose_cfg_t *cfg, void *buf, size_t *len)
Creates a new IO object which collects data into a static buffer.
jose_io_malloc_steal
void * jose_io_malloc_steal(void **buf)
Steals the buffer created by the jose_io_malloc() IO object.
jose_io_t
The interface for chained IO.
Definition: io.h:61
jose_io_auto_t
jose_io_t jose_io_auto_t
Defines a jose_io_t which calls jose_io_decref() at end of scope.
Definition: io.h:43