File: buffer.h

package info (click to toggle)
innfeed 0.10.1.7-7
  • links: PTS
  • area: main
  • in suites: woody
  • size: 892 kB
  • ctags: 1,603
  • sloc: ansic: 13,280; yacc: 846; perl: 369; lex: 250; makefile: 238; sh: 163
file content (141 lines) | stat: -rw-r--r-- 5,559 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* -*- c -*-
 *
 * Author:      James Brister <brister@vix.com> -- berkeley-unix --
 * Start Date:  Wed Dec 27 11:02:04 1995
 * Project:     INN (innfeed)
 * File:        buffer.h
 * RCSId:       $Id: buffer.h,v 1.1.1.1 1997/04/29 16:13:31 scrappy Exp $
 *
 * Copyright:   Copyright (c) 1996 by Internet Software Consortium
 *
 *              Permission to use, copy, modify, and distribute this
 *              software for any purpose with or without fee is hereby
 *              granted, provided that the above copyright notice and this
 *              permission notice appear in all copies.
 *
 *              THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE
 *              CONSORTIUM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
 *              SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 *              MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET
 *              SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
 *              INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 *              WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 *              WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 *              TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
 *              USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 * Description: The public interface to the Buffer class.
 * 
 *              The Buffer class encapsulates a region of memory. It
 *              provides reference counting so that redundant
 *              memory allocation and copying is minimized. A good
 *              example of this is the need to write the same data
 *              (e.g. an article body) out more than one socket. The
 *              data is stored in a Buffer and the Buffer is given
 *              to each EndPoint that is to write it. With the
 *              Refcount appropriately set the EndPoints can release
 *              their references at will and the Buffer will be
 *              cleaned up when necessary.
 */

#if ! defined ( buffer_h__ )
#define buffer_h__


#include <sys/types.h>
#include <stdio.h>

#include "misc.h"


/*
 * Create a new Buffer object and initialize it.
 */
Buffer newBuffer (size_t size) ;

/* Create a new Buffer object around the preallocted PTR, which is SIZE
   bytes long. The data size of the Buffer is set to DATASIZE. When then
   buffer is released it will not delete the ptr (this is useful to have
   Buffers around contant strings, or Buffers around other Buffers) */
Buffer newBufferByCharP (const char *ptr, size_t size, size_t dataSize) ;

/*
 * give up interest in the Buffer. Decrement refcount and delete if no
 * more referants
 */
void delBuffer (Buffer buff) ;

  /* print some debugging information about the buffer. */
void printBufferInfo (Buffer buffer, FILE *fp, u_int indentAmt) ;

  /* print debugging information about all outstanding buffers. */
void gPrintBufferInfo (FILE *fp, u_int indentAmt) ;

/* increment reference counts so that the buffer object can be */
/* handed off to another function without it being deleted when that */
/* function calls bufferDelete(). Returns buff, so the call can be */
/* used in function arg list. */
Buffer bufferTakeRef (Buffer buff) ;

/* returns the address of the base of the memory owned by the Buffer */
void *bufferBase (Buffer buff) ;

/* returns the size of the memory buffer has available. This always returns
   1 less than the real size so that there's space left for a null byte
   when needed. The extra byte is accounted for when the newBuffer function
   is called. */
size_t bufferSize (Buffer) ;

/* return the amount of data actually in the buffer */
size_t bufferDataSize (Buffer buff) ;

/* increment the size of the buffer's data region */
void bufferIncrDataSize (Buffer buff, size_t size) ;

/* decrement the size of the buffer's data region */
void bufferDecrDataSize (Buffer buff, size_t size) ;

/* set the size of the data actually in the buffer */
void bufferSetDataSize (Buffer buff, size_t size) ;

/* walk down the BUFFS releasing each buffer and then freeing BUFFS itself */
void freeBufferArray (Buffer *buffs) ;

/* All arguments are non-NULL Buffers, except for the last which must be
   NULL. Creates a free'able array and puts all the buffers into it (does
   not call bufferTakeRef on them). */
Buffer *makeBufferArray (Buffer buff, ...) ;

/* returns true if the buffer was created via
   newBuffer (vs. newBufferByCharP) */
bool isDeletable (Buffer buff) ;

/* Dups the array including taking out references on the Buffers
   inside. Return value must be freed (or given to freeBufferArray) */
Buffer *dupBufferArray (Buffer *array) ;

/* return the number of non-NULL elements in the array. */
u_int bufferArrayLen (Buffer *array) ;

/* copies the contents of the SRC buffer into the DEST buffer and sets the
   data size appropriately. Returns false if src is bigger than dest. */
bool copyBuffer (Buffer dest, Buffer src) ;

/* return the ref count on the buffer */
u_int bufferRefCount (Buffer buff) ;

/* insert a null byte at the end of the data region */
void bufferAddNullByte (Buffer buff) ;

/* append the data of src to the data of dest, if dest is big enough */
bool concatBuffer (Buffer dest, Buffer src) ;

/* expand the buffer's memory by the given AMT */
bool expandBuffer (Buffer buff, size_t amt) ;

/* Expand the buffer (if necessary) and insert carriage returns before very
   line feed. Adjusts the data size. The base address may change
   afterwards. */
bool nntpPrepareBuffer (Buffer buffer) ;

#endif /* buffer_h__ */