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
69 XrdOucBuffer *Alloc(int sz);
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
114struct BuffSlot
115 {XrdSysMutex SlotMutex;
116 XrdOucBuffer *buffFree;
117 int size;
118 short numbuff;
119 short maxbuff;
120
121 void Recycle(XrdOucBuffer *bP);
122
123 BuffSlot() : buffFree(0), size(0),
124 numbuff(0), maxbuff(0) {}
125 ~BuffSlot();
126 };
127
128BuffSlot *bSlot;
129int incBsz;
130int shfBsz;
131int rndBsz;
132int maxBsz;
133int slots;
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
173 XrdOucBuffer *Clone(bool trim=true);
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:
260 XrdOucBuffer(XrdOucBuffPool *pP, int snum)
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;
274union{XrdOucBuffer *buffNext;
275 XrdOucBuffPool *buffPool;
276 };
277};
278#endif
void trim(std::string &str)
Definition XrdHttpReq.cc:76
int MaxSize() const
XrdOucBuffer * Alloc(int sz)
char * Data() const
char * Buffer() const
bool Resize(int newsz)
int BuffSize() const
XrdOucBuffer * Clone(bool trim=true)
void Recycle()
Recycle the buffer. The buffer may be reused in the future.
XrdOucBuffer * Highjack(int bPsz=0)
char * Data(int &dataL) const
void SetLen(int dataL, int dataO=0)