xrootd
Loading...
Searching...
No Matches
XrdOucBuffer.hh
Go to the documentation of this file.
1#ifndef __OUC_BUFF__
2#define __OUC_BUFF__
3/******************************************************************************/
4/* */
5/* X r d O u c B u f f e r . h h */
6/* */
7/* (c) 2013 by the Board of Trustees of the Leland Stanford, Jr., University */
8/* All Rights Reserved */
9/* Produced by Andrew Hanushevsky for Stanford University under contract */
10/* DE-AC02-76-SFO0515 with the Department of Energy */
11/* */
12/* This file is part of the XRootD software suite. */
13/* */
14/* XRootD is free software: you can redistribute it and/or modify it under */
15/* the terms of the GNU Lesser General Public License as published by the */
16/* Free Software Foundation, either version 3 of the License, or (at your */
17/* option) any later version. */
18/* */
19/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22/* License for more details. */
23/* */
24/* You should have received a copy of the GNU Lesser General Public License */
25/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27/* */
28/* The copyright holder's institutional names and contributor's names may not */
29/* be used to endorse or promote products derived from this software without */
30/* specific prior written permission of the institution or contributor. */
31/******************************************************************************/
32
33#include <cstdlib>
34
35#include "XrdOuc/XrdOucChain.hh"
37
38/******************************************************************************/
39/* X r d O u c B u f f P o o l */
40/******************************************************************************/
41
42class XrdOucBuffer;
43
44//-----------------------------------------------------------------------------
52//-----------------------------------------------------------------------------
53
55{
56friend class XrdOucBuffer;
57public:
58
59//-----------------------------------------------------------------------------
67//-----------------------------------------------------------------------------
68
70
71//-----------------------------------------------------------------------------
75//-----------------------------------------------------------------------------
76
77inline int MaxSize() const {return maxBsz;}
78
79//-----------------------------------------------------------------------------
98//-----------------------------------------------------------------------------
99
100 XrdOucBuffPool(int minsz=4096, int maxsz=65536,
101 int minh=1, int maxh=16,
102 int rate=1);
103
104//-----------------------------------------------------------------------------
107//-----------------------------------------------------------------------------
108
109 ~XrdOucBuffPool() {delete [] bSlot;}
110
111private:
112static int alignit;
113
127
134};
135
136/******************************************************************************/
137/* X r d O u c B u f f e r */
138/******************************************************************************/
139
141{
142friend class XrdOucBuffPool;
143
144public:
145
146//-----------------------------------------------------------------------------
150//-----------------------------------------------------------------------------
151
152inline char *Buffer() const {return data;}
153
154//-----------------------------------------------------------------------------
158//-----------------------------------------------------------------------------
159
160inline int BuffSize() const {return size;}
161
162//-----------------------------------------------------------------------------
171//-----------------------------------------------------------------------------
172
174
175//-----------------------------------------------------------------------------
179//-----------------------------------------------------------------------------
180
181inline char *Data() const {return data+doff;}
182
183//-----------------------------------------------------------------------------
189//-----------------------------------------------------------------------------
190
191inline char *Data(int &dataL) const {dataL = dlen; return data+doff;}
192
193//-----------------------------------------------------------------------------
197//-----------------------------------------------------------------------------
198
199inline int DataLen() {return dlen;}
200
201//-----------------------------------------------------------------------------
212//-----------------------------------------------------------------------------
213
214 XrdOucBuffer *Highjack(int bPsz=0);
215
216//-----------------------------------------------------------------------------
218//-----------------------------------------------------------------------------
219
220inline void Recycle() {buffPool->bSlot[slot].Recycle(this);}
221
222//-----------------------------------------------------------------------------
230//-----------------------------------------------------------------------------
231
232 bool Resize(int newsz);
233
234//-----------------------------------------------------------------------------
239//-----------------------------------------------------------------------------
240
241inline void SetLen(int dataL, int dataO=0) {dlen = dataL; doff = dataO;}
242
243//-----------------------------------------------------------------------------
255//-----------------------------------------------------------------------------
256
257 XrdOucBuffer(char *buff, int blen);
258
259private:
261 : data(0), dlen(0), doff(0), size(pP->bSlot[snum].size),
262 slot(snum), buffPool(pP) {}
263
265 : data(0), dlen(0), doff(0), size(0), slot(0), buffPool(0) {}
266
267 ~XrdOucBuffer() {if (data) free(data);}
268
269 char *data;
270 int dlen;
271 int doff;
272 int size;
273 int slot;
276 };
277};
278#endif
void trim(std::string &str)
Definition XrdOucBuffer.hh:55
int incBsz
Definition XrdOucBuffer.hh:129
int MaxSize() const
Definition XrdOucBuffer.hh:77
static int alignit
Definition XrdOucBuffer.hh:112
int slots
Definition XrdOucBuffer.hh:133
int rndBsz
Definition XrdOucBuffer.hh:131
XrdOucBuffer * Alloc(int sz)
BuffSlot * bSlot
Definition XrdOucBuffer.hh:128
XrdOucBuffPool(int minsz=4096, int maxsz=65536, int minh=1, int maxh=16, int rate=1)
~XrdOucBuffPool()
Definition XrdOucBuffer.hh:109
int maxBsz
Definition XrdOucBuffer.hh:132
int shfBsz
Definition XrdOucBuffer.hh:130
Definition XrdOucBuffer.hh:141
char * Data() const
Definition XrdOucBuffer.hh:181
char * Buffer() const
Definition XrdOucBuffer.hh:152
XrdOucBuffPool * buffPool
Definition XrdOucBuffer.hh:275
bool Resize(int newsz)
int BuffSize() const
Definition XrdOucBuffer.hh:160
int doff
Definition XrdOucBuffer.hh:271
~XrdOucBuffer()
Definition XrdOucBuffer.hh:267
XrdOucBuffer(char *buff, int blen)
int slot
Definition XrdOucBuffer.hh:273
XrdOucBuffer * Clone(bool trim=true)
XrdOucBuffer * buffNext
Definition XrdOucBuffer.hh:274
void Recycle()
Recycle the buffer. The buffer may be reused in the future.
Definition XrdOucBuffer.hh:220
XrdOucBuffer(XrdOucBuffPool *pP, int snum)
Definition XrdOucBuffer.hh:260
int size
Definition XrdOucBuffer.hh:272
int DataLen()
Definition XrdOucBuffer.hh:199
int dlen
Definition XrdOucBuffer.hh:270
char * data
Definition XrdOucBuffer.hh:269
XrdOucBuffer()
Definition XrdOucBuffer.hh:264
XrdOucBuffer * Highjack(int bPsz=0)
char * Data(int &dataL) const
Definition XrdOucBuffer.hh:191
void SetLen(int dataL, int dataO=0)
Definition XrdOucBuffer.hh:241
Definition XrdSysPthread.hh:165
Definition XrdOucBuffer.hh:115
XrdOucBuffer * buffFree
Definition XrdOucBuffer.hh:116
short maxbuff
Definition XrdOucBuffer.hh:119
int size
Definition XrdOucBuffer.hh:117
XrdSysMutex SlotMutex
Definition XrdOucBuffer.hh:115
short numbuff
Definition XrdOucBuffer.hh:118
BuffSlot()
Definition XrdOucBuffer.hh:123
void Recycle(XrdOucBuffer *bP)