XRootD
XrdOucBuffer Class Reference

#include <XrdOucBuffer.hh>

+ Collaboration diagram for XrdOucBuffer:

Public Member Functions

 XrdOucBuffer (char *buff, int blen)
 
char * Buffer () const
 
int BuffSize () const
 
XrdOucBufferClone (bool trim=true)
 
char * Data () const
 
char * Data (int &dataL) const
 
int DataLen ()
 
XrdOucBufferHighjack (int bPsz=0)
 
void Recycle ()
 Recycle the buffer. The buffer may be reused in the future. More...
 
bool Resize (int newsz)
 
void SetLen (int dataL, int dataO=0)
 

Friends

class XrdOucBuffPool
 

Detailed Description

Definition at line 140 of file XrdOucBuffer.hh.

Constructor & Destructor Documentation

◆ XrdOucBuffer()

XrdOucBuffer::XrdOucBuffer ( char *  buff,
int  blen 
)

Public constructor. You can create one-time buffers not associated with a buffer pool via new to associated your own storage area that will be freed when the buffer is recycled. This may be handy to pass along such a buffer to XrdOucErrInfo in a pinch. A one-time buffer is restricted and the Clone(), Highjack() and Resize() methods will always fail. However, all the other methods will work in the expected way.

Parameters
buff- pointer to a storage area obtained via posix_memalign() and it will be released via free().
blen- the size of the buffer as well as the data length. Use SetLen() to set a new data length if it differs.

Definition at line 187 of file XrdOucBuffer.cc.

188 {
189  static XrdOucBuffPool nullPool(0, 0, 0, 0, 0);
190 
191 // Initialize the one time buffer
192 //
193  data = buff;
194  dlen = blen;
195  doff = 0;
196  size = blen;
197  slot = 0;
198  buffPool = &nullPool;
199 };

References XrdOucBuffer().

Referenced by XrdOucBuffer().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Function Documentation

◆ Buffer()

char* XrdOucBuffer::Buffer ( ) const
inline

Get the pointer to the buffer.

Returns
pointer to the buffer.

Definition at line 152 of file XrdOucBuffer.hh.

152 {return data;}

Referenced by XrdCmsParser::Decode(), and XrdOfsPrepGPIReal::PrepGPI::query().

+ Here is the caller graph for this function:

◆ BuffSize()

int XrdOucBuffer::BuffSize ( void  ) const
inline

Get the size of the buffer.

Returns
size of the buffer.

Definition at line 160 of file XrdOucBuffer.hh.

160 {return size;}

◆ Clone()

XrdOucBuffer * XrdOucBuffer::Clone ( bool  trim = true)

Produce a clone of this buffer.

Parameters
trim- when true the memory buffer is trimmed to be of sufficient size to hold the actual data. Otherwise, the cloned memory buffer is of the same length.
Returns
!0 - pointer to the cloned buffer. =0 - insufficient memory to clone the buffer.

Definition at line 205 of file XrdOucBuffer.cc.

206 {
207  XrdOucBuffer *newbP;
208  int newsz;
209 
210 // Compute the size of the new buffer
211 //
212  newsz = (trim ? doff+dlen : size);
213 
214 // Allocate a new buffer
215 //
216  if (!(newbP = buffPool->Alloc(newsz))) return 0;
217 
218 // Copy the data and the information
219 //
220  newbP->dlen = dlen;
221  newbP->doff = doff;
222  memcpy(newbP->data, data, dlen+doff);
223  return newbP;
224 }
void trim(std::string &str)
Definition: XrdHttpReq.cc:76

References trim().

Referenced by XrdOucErrInfo::operator=().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Data() [1/2]

char* XrdOucBuffer::Data ( ) const
inline

Get a pointer to the data in the buffer.

Returns
pointer to the data.

Definition at line 181 of file XrdOucBuffer.hh.

181 {return data+doff;}

Referenced by XrdOucErrInfo::getErrText().

+ Here is the caller graph for this function:

◆ Data() [2/2]

char* XrdOucBuffer::Data ( int &  dataL) const
inline

Get a pointer to the data in the buffer and the length of the data.

Parameters
dataL- place where the length is to be stored.
Returns
pointer to the data with dataL holding its length.

Definition at line 191 of file XrdOucBuffer.hh.

191 {dataL = dlen; return data+doff;}

◆ DataLen()

int XrdOucBuffer::DataLen ( )
inline

Get the data length.

Returns
The data length.

Definition at line 199 of file XrdOucBuffer.hh.

199 {return dlen;}

Referenced by XrdCmsParser::Decode(), and XrdOucErrInfo::getErrTextLen().

+ Here is the caller graph for this function:

◆ Highjack()

XrdOucBuffer * XrdOucBuffer::Highjack ( int  bPsz = 0)

Highjack the buffer contents and reinitialize the original buffer.

Parameters
bPsz- the desired size to be given to the highjacked buffer. If zero, the current size is used. Same size resictions apply as for buffer pool Alloc(), above.
Returns
!0 - pointer to a usable buffer object which is identical to the original buffer. The original buffer was reallocated with the specified size.
=0 - insufficient memory to allocate a buffer.

Definition at line 230 of file XrdOucBuffer.cc.

231 {
232  XrdOucBuffer tempBuff, *newbP;
233 
234 // Adjust the size to revert highjacked buffer
235 //
236  if (xsz <= 0) xsz = size;
237 
238 // Allocate a new buffer
239 //
240  if (!(newbP = buffPool->Alloc(xsz))) return 0;
241 
242 // Swap information
243 //
244  tempBuff = *this;
245  *this = *newbP;
246  *newbP = tempBuff;
247  tempBuff.data = 0;
248  return newbP;
249 }

Referenced by XrdCmsParser::Decode(), and Resize().

+ Here is the caller graph for this function:

◆ Recycle()

void XrdOucBuffer::Recycle ( void  )
inline

Recycle the buffer. The buffer may be reused in the future.

Definition at line 220 of file XrdOucBuffer.hh.

220 {buffPool->bSlot[slot].Recycle(this);}

Referenced by XrdCmsClientMan::~XrdCmsClientMan(), XrdOfsPrepGPIReal::PrepGPI::query(), XrdOucErrInfo::Reset(), Resize(), and XrdOucErrInfo::setErrInfo().

+ Here is the caller graph for this function:

◆ Resize()

bool XrdOucBuffer::Resize ( int  newsz)

Resize the buffer.

Parameters
newsz- the size that the buffer is to have. The same restrictions apply as for buffer pool Alloc(), above.
Returns
true - buffer has been reallocated.
false - insufficient memoy to reallocated the buffer.

Definition at line 255 of file XrdOucBuffer.cc.

256 {
257 
258 // If the new size differs from the old size, reallocate by simply highjacking
259 // the buffer and releasing the newly acquired one.
260 //
261  if (newsz != size)
262  {XrdOucBuffer *newbP;
263  if (!(newbP = Highjack(newsz))) return false;
264  newbP->Recycle();
265  }
266  return true;
267 }
void Recycle()
Recycle the buffer. The buffer may be reused in the future.
XrdOucBuffer * Highjack(int bPsz=0)

References Highjack(), and Recycle().

+ Here is the call graph for this function:

◆ SetLen()

void XrdOucBuffer::SetLen ( int  dataL,
int  dataO = 0 
)
inline

Set the data length of offset.

Parameters
dataL- the length of the data.
dataO- the offset of the data in the buffer.

Definition at line 241 of file XrdOucBuffer.hh.

241 {dlen = dataL; doff = dataO;}

Referenced by XrdCmsParser::Decode().

+ Here is the caller graph for this function:

Friends And Related Function Documentation

◆ XrdOucBuffPool

friend class XrdOucBuffPool
friend

Definition at line 142 of file XrdOucBuffer.hh.


The documentation for this class was generated from the following files: