23 packettrim \- zero-copy network buffers
31 .ta +\w'\fLPacket* 'u +\w'\fLxxxx'u
36 Packet* packetalloc(void);
39 void packetappend(Packet *p, uchar *buf, int n)
42 uint packetasize(Packet *p)
45 int packetcmp(Packet *p, Packet *q)
48 void packetconcat(Packet *p, Packet *q)
51 int packetconsume(Packet *p, uchar *buf, int n)
54 int packetcopy(Packet *p, uchar *buf, int offset, int n)
57 Packet* packetdup(Packet *p, int offset, int n)
60 Packet* packetforeign(uchar *buf, int n,
63 void (*free)(void *a), void *a)
66 int packetfragments(Packet *p, IOchunk *io, int nio,
72 void packetfree(Packet *p)
75 uchar* packetheader(Packet *p, int n)
78 uchar* packetpeek(Packet *p, uchar *buf, int offset, int n)
81 void packetprefix(Packet *p, uchar *buf, int n)
84 void packetsha1(Packet *p, uchar sha1[20])
87 uint packetsize(Packet *p)
90 Packet* packetsplit(Packet *p, int n)
93 void packetstats(void)
96 uchar* packettrailer(Packet *p, int n)
99 int packettrim(Packet *p, int offset, int n)
103 is a chain of blocks of data.
104 Each block, called a fragment,
105 is contiguous in memory, but the entire packet
107 This representation helps avoid unnecessary memory copies.
110 allocates an empty packet.
121 returns the number of data bytes allocated to
123 This may be larger than the number of bytes stored
126 because fragments may not be filled completely.
129 compares the data sections of two packets as
136 removes all data from
144 bytes from the beginning of
160 creates a new packet initialized with
168 allocates a packet containing `foreign' data: the
172 Once the bytes are no longer needed, they are freed by calling
180 structures with pointers to the data in
184 It returns the total number of bytes represented
185 by the returned structures.
187 initializes any unused
189 structures with nil pointer and zero length.
196 returns a pointer to the first
200 making them contiguous in memory
204 returns a pointer to the
210 If the requested bytes are already stored contiguously in memory,
211 the returned pointer points at the internal data storage for
213 Otherwise, the bytes are copied into
221 inserts a copy of the
229 computes the SHA1 hash of the data contained in
233 returns the length, in bytes, of the data contained in
237 returns a new packet initialized with
239 bytes removed from the beginning of
243 prints run-time statistics to standard output.
246 returns a pointer to the last
250 making them contiguous in memory
254 deletes all bytes from the packet
265 These functions return errors only when passed
268 requests for data at negative offsets or beyond the end of a packet.
270 Functions returning pointers return nil on error;
271 functions returning integers return \-1 on error.
272 Most functions returning integers return 0 on success.
277 whose return values are described above.
279 When these functions run out of memory, they
280 print error messages and call