PostgreSQL Source Code git master
mbuf.h
Go to the documentation of this file.
1/*
2 * mbuf.h
3 * Memory buffer operations.
4 *
5 * Copyright (c) 2005 Marko Kreen
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * contrib/pgcrypto/mbuf.h
30 */
31
32#ifndef __PX_MBUF_H
33#define __PX_MBUF_H
34
35typedef struct MBuf MBuf;
36typedef struct PushFilter PushFilter;
37typedef struct PullFilter PullFilter;
40
42{
43 /*
44 * should return needed buffer size, 0- no buffering, <0 on error if NULL,
45 * no buffering, and priv=init_arg
46 */
47 int (*init) (PushFilter *next, void *init_arg, void **priv_p);
48
49 /*
50 * send data to next. should consume all? if null, it will be simply
51 * copied (in-place) returns 0 on error
52 */
53 int (*push) (PushFilter *next, void *priv,
54 const uint8 *src, int len);
55 int (*flush) (PushFilter *next, void *priv);
56 void (*free) (void *priv);
57};
58
60{
61 /*
62 * should return needed buffer size, 0- no buffering, <0 on error if NULL,
63 * no buffering, and priv=init_arg
64 */
65 int (*init) (void **priv_p, void *init_arg, PullFilter *src);
66
67 /*
68 * request data from src, put result ptr to data_p can use ptr from src or
69 * use buf as work area if NULL in-place copy
70 */
71 int (*pull) (void *priv, PullFilter *src, int len,
72 uint8 **data_p, uint8 *buf, int buflen);
73 void (*free) (void *priv);
74};
75
76/*
77 * Memory buffer
78 */
79MBuf *mbuf_create(int len);
81int mbuf_avail(MBuf *mbuf);
82int mbuf_size(MBuf *mbuf);
83int mbuf_grab(MBuf *mbuf, int len, uint8 **data_p);
84int mbuf_steal_data(MBuf *mbuf, uint8 **data_p);
85int mbuf_append(MBuf *dst, const uint8 *buf, int len);
86int mbuf_free(MBuf *mbuf);
87
88/*
89 * Push filter
90 */
91int pushf_create(PushFilter **mp_p, const PushFilterOps *op,
92 void *init_arg, PushFilter *next);
93int pushf_write(PushFilter *mp, const uint8 *data, int len);
95void pushf_free(PushFilter *mp);
96int pushf_flush(PushFilter *mp);
97
99
100/*
101 * Pull filter
102 */
103int pullf_create(PullFilter **pf_p, const PullFilterOps *op,
104 void *init_arg, PullFilter *src);
105int pullf_read(PullFilter *pf, int len, uint8 **data_p);
106int pullf_read_max(PullFilter *pf, int len,
107 uint8 **data_p, uint8 *tmpbuf);
108void pullf_free(PullFilter *pf);
109int pullf_read_fixed(PullFilter *src, int len, uint8 *dst);
110
112
113#define GETBYTE(pf, dst) \
114 do { \
115 uint8 __b; \
116 int __res = pullf_read_fixed(pf, 1, &__b); \
117 if (__res < 0) \
118 return __res; \
119 (dst) = __b; \
120 } while (0)
121
122#endif /* __PX_MBUF_H */
static int32 next
Definition: blutils.c:219
uint8_t uint8
Definition: c.h:486
int pullf_read_fixed(PullFilter *src, int len, uint8 *dst)
Definition: mbuf.c:301
int pullf_create(PullFilter **pf_p, const PullFilterOps *op, void *init_arg, PullFilter *src)
Definition: mbuf.c:191
int pushf_write(PushFilter *mp, const uint8 *data, int len)
Definition: mbuf.c:439
int mbuf_avail(MBuf *mbuf)
Definition: mbuf.c:50
int pushf_create(PushFilter **mp_p, const PushFilterOps *op, void *init_arg, PushFilter *next)
Definition: mbuf.c:357
int pullf_read_max(PullFilter *pf, int len, uint8 **data_p, uint8 *tmpbuf)
Definition: mbuf.c:263
int mbuf_free(MBuf *mbuf)
Definition: mbuf.c:62
int pullf_create_mbuf_reader(PullFilter **mp_p, MBuf *src)
Definition: mbuf.c:336
int mbuf_append(MBuf *dst, const uint8 *buf, int len)
Definition: mbuf.c:94
int pullf_read(PullFilter *pf, int len, uint8 **data_p)
Definition: mbuf.c:246
int pushf_create_mbuf_writer(PushFilter **res, MBuf *dst)
Definition: mbuf.c:544
MBuf * mbuf_create_from_data(uint8 *data, int len)
Definition: mbuf.c:131
int mbuf_steal_data(MBuf *mbuf, uint8 **data_p)
Definition: mbuf.c:162
MBuf * mbuf_create(int len)
Definition: mbuf.c:111
void pushf_free_all(PushFilter *mp)
Definition: mbuf.c:411
int pushf_flush(PushFilter *mp)
Definition: mbuf.c:499
int mbuf_size(MBuf *mbuf)
Definition: mbuf.c:56
int mbuf_grab(MBuf *mbuf, int len, uint8 **data_p)
Definition: mbuf.c:149
void pushf_free(PushFilter *mp)
Definition: mbuf.c:395
void pullf_free(PullFilter *pf)
Definition: mbuf.c:229
const void size_t len
const void * data
static char * buf
Definition: pg_test_fsync.c:72
Definition: mbuf.c:40
void(* free)(void *priv)
Definition: mbuf.h:73
int(* init)(void **priv_p, void *init_arg, PullFilter *src)
Definition: mbuf.h:65
int(* pull)(void *priv, PullFilter *src, int len, uint8 **data_p, uint8 *buf, int buflen)
Definition: mbuf.h:71
int(* flush)(PushFilter *next, void *priv)
Definition: mbuf.h:55
void(* free)(void *priv)
Definition: mbuf.h:56
int(* init)(PushFilter *next, void *init_arg, void **priv_p)
Definition: mbuf.h:47
int(* push)(PushFilter *next, void *priv, const uint8 *src, int len)
Definition: mbuf.h:53
static StringInfoData tmpbuf
Definition: walsender.c:170