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 {
64  error
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 */
A collection of assert function wrappers.
Class IPv4Socket covers domain types AF_INET and AF_UNIX.
#define trace_with_mask(s, m)
trace_with_mask() is used to trace function call chain in C++ program.
Definition: Logger.h:437
unsigned int u_int
Definition: Logger_Impl.h:40
Abstraction of socket data type.
void copy(const xdrIOBuffer &)
Copy object from argument.
xdrIOBuffer(u_int len_)
Constructor.
Definition: xdrIOBuffer.cpp:79
void reset()
Clear up the internal buffer and reset state to waiting.
friend Socket & operator>>(Socket &src_, xdrIOBuffer &dest_)
Read raw data from Socket nonblocking and store into internal buffer.
Definition: xdrIOBuffer.cpp:25
int m_sz
Buffer size and maximum expected size.
Definition: xdrIOBuffer.h:140
char * m_ptr
Pointer for next I/O operation into the buffer
Definition: xdrIOBuffer.h:143
int size() const
Return number of bytes in xdrIOBuffer.
Definition: xdrIOBuffer.h:171
~xdrIOBuffer()
Destructor.
Definition: xdrIOBuffer.cpp:93
state_t m_state
Object state.
Definition: xdrIOBuffer.h:146
const char * str() const
Return pointer to the first byte of xdrIOBuffer.
Definition: xdrIOBuffer.h:185
char * m_buf
Buffer.
Definition: xdrIOBuffer.h:137
string get_state() const
Give verbal interpretation of object's state.
xdrIOBuffer & operator=(const xdrIOBuffer &rhs_)
Assign operator.
void dump() const
Dump object's internal state to the log file.
int buffer_size() const
Return buffer (maximum expected/allowable) size.
Definition: xdrIOBuffer.h:178
Definition: Acceptor.h:40
@ XDRBUFTRACE
Extended xdrIOBuffer messages
Definition: LogMask.h:44