/usr/include/assa-3.5/assa/xdrIOBuffer.h is in libassa-3.5-5-dev 3.5.1-6build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | // -*- c++ -*-
//------------------------------------------------------------------------------
// xdrIOBuffer.h
//------------------------------------------------------------------------------
// Copyright (c) 2000,2005 by Vladislav Grinchenko
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//------------------------------------------------------------------------------
// Created: 04/03/2000
//------------------------------------------------------------------------------
#ifndef XDR_IO_BUFFER_H
#define XDR_IO_BUFFER_H
#include "assa/Assure.h"
#include "assa/Socket.h"
#include "assa/IPv4Socket.h"
#include <string>
namespace ASSA {
/** @file xdrIOBuffer.h
*
* This class allows to read XDR-encoded data from Socket stream asynchronously
* and then read from it as if from a stream of intermixed strings, integers
* and floats. Data are XDR-decoded on a fly.
*
* Testing xdrIOBuffer object in conditional statement will produce
* false if:
*
* - Not entire buffer has been read yet.
* - Socket stream exceptional condition occured.
*
* Thus, data accumulation and data decoding functions are separated.
*
* Initially, buffer is in waiting state. In this state,
* xdrIOBuffer object waits for bytes from the Socket stream.
*
* When buffer object becomes full, the state is switched to
* xmitted. Now, an application code can read data
* from the buffer. The data will be XDR-decoded.
*
* xdrIOBuffer object yields TRUE in conditional statements only
* in xmitted state. In other words, buffer is TRUE if
* it is full, and FALSE otherwise.
*
* xdrIOBuffer can be used only once. You cannot "rewind", and therefore
* reuse it.
*/
class xdrIOBuffer
{
public:
/** @enum state_t
*/
enum state_t {
waiting,
xmitted,
parsed,
error
};
/** Constructor.
*/
xdrIOBuffer (u_int len_);
/** Destructor.
*/
~xdrIOBuffer ();
/** Copy constructor
*/
xdrIOBuffer (const xdrIOBuffer& rhs_);
/** Assign operator.
*/
xdrIOBuffer& operator= (const xdrIOBuffer& rhs_);
/** Read raw data from Socket nonblocking and
* store into internal buffer.
*/
friend Socket& operator>>(Socket& src_, xdrIOBuffer& dest_);
/** Read and XDR-decode STL string from the buffer.
*/
xdrIOBuffer& operator>>(std::string&);
/** Read and XDR-decode an integer from the buffer.
*/
xdrIOBuffer& operator>>(int&);
/** Read and XDR-decode a float from the buffer.
*/
xdrIOBuffer& operator>>(float&);
/** Convertion to void* (for testing where bool is required).
*/
operator void*() const;
/** Give verbal interpretation of object's state.
*/
string get_state () const;
/** Return number of bytes in xdrIOBuffer. In <b>waiting</b>
state it's bytes transmitted so far. In <b>xmitted</b> state,
number of bytes left to decode.
*/
int size () const;
/** Return buffer (maximum expected/allowable) size.
*/
int buffer_size () const;
/** Return pointer to the first byte of xdrIOBuffer.
*/
const char* str () const;
/** Clear up the internal buffer and reset state to
<b>waiting</b>.
*/
void reset ();
/** Dump object's internal state to the log file
*/
void dump () const;
protected:
/// Copy object from argument
void copy (const xdrIOBuffer&);
private:
/// Buffer
char* m_buf;
/// Buffer size and maximum expected size
int m_sz;
/// Pointer for next I/O operation into the buffer
char* m_ptr;
/// Object state
state_t m_state;
};
inline
xdrIOBuffer::
xdrIOBuffer (const xdrIOBuffer& rhs_)
{
trace_with_mask("xdrIOBuffer::xdrIOBuffer(xdrIOBuffer&)", XDRBUFTRACE);
copy (rhs_);
}
inline
xdrIOBuffer::
operator void*() const
{
trace_with_mask("xdrIOBuffer::opt void*()", XDRBUFTRACE);
return (m_state == waiting || m_state == parsed)
? (void *)0 // bad state
: (void *)(-1); // good state
}
inline int
xdrIOBuffer::
size () const
{
return (m_ptr - m_buf);
}
inline int
xdrIOBuffer::
buffer_size () const
{
return (m_sz);
}
inline const char*
xdrIOBuffer::
str () const
{
return ((const char*) m_buf);
}
} // end namespace ASSA
#endif /* XDR_IO_BUFFER_H */
|