libassa  3.5.1
xdrIOBuffer.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 //------------------------------------------------------------------------------
3 // xdrIOBuffer.h
4 //------------------------------------------------------------------------------
5 // Copyright (c) 2000,2005 by Vladislav Grinchenko
6 //
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Library General Public
9 // License as published by the Free Software Foundation; either
10 // version 2 of the License, or (at your option) any later version.
11 //------------------------------------------------------------------------------
12 // Created: 04/03/2000
13 //------------------------------------------------------------------------------
14 
15 #ifndef XDR_IO_BUFFER_H
16 #define XDR_IO_BUFFER_H
17 
18 #include "assa/Assure.h"
19 #include "assa/Socket.h"
20 #include "assa/IPv4Socket.h"
21 
22 #include <string>
23 
24 namespace ASSA {
25 
56 {
57 public:
60  enum state_t {
65  };
66 
69  xdrIOBuffer (u_int len_);
70 
73  ~xdrIOBuffer ();
74 
77  xdrIOBuffer (const xdrIOBuffer& rhs_);
78 
81  xdrIOBuffer& operator= (const xdrIOBuffer& rhs_);
82 
86  friend Socket& operator>>(Socket& src_, xdrIOBuffer& dest_);
87 
90  xdrIOBuffer& operator>>(std::string&);
91 
94  xdrIOBuffer& operator>>(int&);
95 
98  xdrIOBuffer& operator>>(float&);
99 
102  operator void*() const;
103 
106  string get_state () const;
107 
112  int size () const;
113 
116  int buffer_size () const;
117 
120  const char* str () const;
121 
125  void reset ();
126 
129  void dump () const;
130 
131 protected:
133  void copy (const xdrIOBuffer&);
134 
135 private:
137  char* m_buf;
138 
140  int m_sz;
141 
143  char* m_ptr;
144 
147 };
148 
149 inline
151 xdrIOBuffer (const xdrIOBuffer& rhs_)
152 {
153  trace_with_mask("xdrIOBuffer::xdrIOBuffer(xdrIOBuffer&)", XDRBUFTRACE);
154 
155  copy (rhs_);
156 }
157 
158 inline
159 xdrIOBuffer::
160 operator void*() const
161 {
162  trace_with_mask("xdrIOBuffer::opt void*()", XDRBUFTRACE);
163 
164  return (m_state == waiting || m_state == parsed)
165  ? (void *)0 // bad state
166  : (void *)(-1); // good state
167 }
168 
169 inline int
171 size () const
172 {
173  return (m_ptr - m_buf);
174 }
175 
176 inline int
178 buffer_size () const
179 {
180  return (m_sz);
181 }
182 
183 inline const char*
185 str () const
186 {
187  return ((const char*) m_buf);
188 }
189 
190 } // end namespace ASSA
191 
192 #endif /* XDR_IO_BUFFER_H */
ASSA::xdrIOBuffer::error
@ error
Definition: xdrIOBuffer.h:64
ASSA::xdrIOBuffer::m_buf
char * m_buf
Buffer.
Definition: xdrIOBuffer.h:137
ASSA::xdrIOBuffer::state_t
state_t
Definition: xdrIOBuffer.h:60
u_int
unsigned int u_int
Definition: Logger_Impl.h:40
ASSA::xdrIOBuffer::xdrIOBuffer
xdrIOBuffer(u_int len_)
Constructor.
Definition: xdrIOBuffer.cpp:79
ASSA::xdrIOBuffer::reset
void reset()
Clear up the internal buffer and reset state to waiting.
Definition: xdrIOBuffer.cpp:199
ASSA::xdrIOBuffer
Definition: xdrIOBuffer.h:55
ASSA::xdrIOBuffer::waiting
@ waiting
Definition: xdrIOBuffer.h:61
ASSA::xdrIOBuffer::buffer_size
int buffer_size() const
Return buffer (maximum expected/allowable) size.
Definition: xdrIOBuffer.h:178
ASSA::xdrIOBuffer::parsed
@ parsed
Definition: xdrIOBuffer.h:63
ASSA::xdrIOBuffer::operator>>
friend Socket & operator>>(Socket &src_, xdrIOBuffer &dest_)
Read raw data from Socket nonblocking and store into internal buffer.
Definition: xdrIOBuffer.cpp:25
ASSA::xdrIOBuffer::get_state
string get_state() const
Give verbal interpretation of object's state.
Definition: xdrIOBuffer.cpp:210
ASSA::xdrIOBuffer::dump
void dump() const
Dump object's internal state to the log file.
Definition: xdrIOBuffer.cpp:225
ASSA::xdrIOBuffer::operator=
xdrIOBuffer & operator=(const xdrIOBuffer &rhs_)
Assign operator.
Definition: xdrIOBuffer.cpp:102
Socket.h
ASSA::XDRBUFTRACE
@ XDRBUFTRACE
Extended xdrIOBuffer messages
Definition: LogMask.h:44
IPv4Socket.h
ASSA::xdrIOBuffer::m_ptr
char * m_ptr
Pointer for next I/O operation into the buffer
Definition: xdrIOBuffer.h:143
ASSA::xdrIOBuffer::str
const char * str() const
Return pointer to the first byte of xdrIOBuffer.
Definition: xdrIOBuffer.h:185
ASSA::xdrIOBuffer::~xdrIOBuffer
~xdrIOBuffer()
Destructor.
Definition: xdrIOBuffer.cpp:93
ASSA::xdrIOBuffer::copy
void copy(const xdrIOBuffer &)
Copy object from argument.
Definition: xdrIOBuffer.cpp:113
Assure.h
ASSA::xdrIOBuffer::xmitted
@ xmitted
Definition: xdrIOBuffer.h:62
ASSA::xdrIOBuffer::m_sz
int m_sz
Buffer size and maximum expected size.
Definition: xdrIOBuffer.h:140
ASSA::xdrIOBuffer::size
int size() const
Return number of bytes in xdrIOBuffer.
Definition: xdrIOBuffer.h:171
ASSA::xdrIOBuffer::m_state
state_t m_state
Object state.
Definition: xdrIOBuffer.h:146
ASSA::Socket
Definition: Socket.h:71
ASSA
Definition: Acceptor.h:40
trace_with_mask
#define trace_with_mask(s, m)
Definition: Logger.h:437