Loading...
Searching...
No Matches
XrdOucBuffer Class Reference

`#include <XrdOucBuffer.hh>`

Collaboration diagram for XrdOucBuffer:

## Public Member Functions

| XrdOucBuffer (char *buff, int blen)
char * | Buffer () const
int | BuffSize () const
XrdOucBuffer * | Clone (bool trim=true)
char * | Data () const
char * | Data (int &dataL) const
int | DataLen ()
XrdOucBuffer * | Highjack (int bPsz=0)
void | Recycle ()
| Recycle the buffer. The buffer may be reused in the future.
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.

{
static XrdOucBuffPool nullPool(0, 0, 0, 0, 0);
// Initialize the one time buffer
//
data = buff;
dlen = blen;
doff = 0;
size = blen;
slot = 0;
buffPool = &nullPool;
};
XrdOucBuffer::XrdOucBuffPool
friend class XrdOucBuffPool
Definition XrdOucBuffer.hh:142

References XrdOucBuffPool.

Referenced by Clone(), Highjack(), and Resize().

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.

{return data;}

Referenced by XrdCmsParser::Decode().

Here is the caller graph for this function:

## BuffSize()

int XrdOucBuffer::BuffSize | ( |  | ) | const

inline

Get the size of the buffer.

Returns
  size of the buffer.

Definition at line 160 of file XrdOucBuffer.hh.

{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.

{
XrdOucBuffer *newbP;
int newsz;
// Compute the size of the new buffer
//
newsz = (trim ? doff+dlen : size);
// Allocate a new buffer
//
if (!(newbP = buffPool->Alloc(newsz))) return 0;
// Copy the data and the information
//
newbP->dlen = dlen;
newbP->doff = doff;
memcpy(newbP->data, data, dlen+doff);
return newbP;
}
trim
void trim(std::string &str)
Definition XrdHttpReq.cc:77
XrdOucBuffer::XrdOucBuffer
XrdOucBuffer(char *buff, int blen)
Definition XrdOucBuffer.cc:187

References XrdOucBuffer(), and 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.

{return data+doff;}

## 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.

{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.

{return dlen;}

Referenced by XrdCmsParser::Decode().

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.

{
XrdOucBuffer tempBuff, *newbP;
// Adjust the size to revert highjacked buffer
//
if (xsz <= 0) xsz = size;
// Allocate a new buffer
//
if (!(newbP = buffPool->Alloc(xsz))) return 0;
// Swap information
//
tempBuff = *this;
*this = *newbP;
*newbP = tempBuff;
tempBuff.data = 0;
return newbP;
}

References XrdOucBuffer().

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

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

## Recycle()

void XrdOucBuffer::Recycle | ( |  | ) |

inline

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

Definition at line 220 of file XrdOucBuffer.hh.

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

Referenced by XrdOfsPrepGPIReal::PrepGPI::query(), and Resize().

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.

{
// If the new size differs from the old size, reallocate by simply highjacking
// the buffer and releasing the newly acquired one.
//
if (newsz != size)
{XrdOucBuffer *newbP;
if (!(newbP = Highjack(newsz))) return false;
newbP->Recycle();
}
return true;
}
XrdOucBuffer::Recycle
void Recycle()
Recycle the buffer. The buffer may be reused in the future.
Definition XrdOucBuffer.hh:220
XrdOucBuffer::Highjack
XrdOucBuffer * Highjack(int bPsz=0)
Definition XrdOucBuffer.cc:230

References XrdOucBuffer(), 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.

{dlen = dataL; doff = dataO;}

Referenced by XrdCmsParser::Decode().

Here is the caller graph for this function:

## Friends And Related Symbol Documentation

## XrdOucBuffPool

friend class XrdOucBuffPool

friend

Definition at line 142 of file XrdOucBuffer.hh.

References XrdOucBuffPool.

Referenced by XrdOucBuffer(), and XrdOucBuffPool.

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

- XrdOucBuffer.hh
- XrdOucBuffer.cc