Loading...
Searching...
No Matches
xdrIOBuffer.h
Go to the documentation of this file.
// -*- 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 {
class xdrIOBuffer
{
public:
enum state_t {
waiting,
xmitted,
parsed,
error
};
xdrIOBuffer (u_int len_);
~xdrIOBuffer ();
xdrIOBuffer (const xdrIOBuffer& rhs_);
xdrIOBuffer& operator= (const xdrIOBuffer& rhs_);
friend Socket& operator>>(Socket& src_, xdrIOBuffer& dest_);
xdrIOBuffer& operator>>(std::string&);
xdrIOBuffer& operator>>(int&);
xdrIOBuffer& operator>>(float&);
operator void*() const;
string get_state () const;
int size () const;
int buffer_size () const;
const char* str () const;
void reset ();
void dump () const;
protected:
void copy (const xdrIOBuffer&);
private:
char* m_buf;
int m_sz;
char* m_ptr;
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 */
Assure.h
A collection of assert function wrappers.
IPv4Socket.h
Class IPv4Socket covers domain types AF_INET and AF_UNIX.
trace_with_mask
#define trace_with_mask(s, m)
trace_with_mask() is used to trace function call chain in C++ program.
Definition Logger.h:437
Socket.h
Abstraction of socket data type.
ASSA::AutoPtrRef
A wrapper class to provide AutoPtr with reference semantics.
Definition AutoPtr.h:32
ASSA::Socket
Definition Socket.h:71
ASSA::xdrIOBuffer
Definition xdrIOBuffer.h:56
ASSA::xdrIOBuffer::copy
void copy(const xdrIOBuffer &)
Copy object from argument.
Definition xdrIOBuffer.cpp:113
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::m_sz
int m_sz
Buffer size and maximum expected size.
Definition xdrIOBuffer.h:140
ASSA::xdrIOBuffer::m_ptr
char * m_ptr
Pointer for next I/O operation into the buffer
Definition xdrIOBuffer.h:143
ASSA::xdrIOBuffer::size
int size() const
Return number of bytes in xdrIOBuffer.
Definition xdrIOBuffer.h:171
ASSA::xdrIOBuffer::~xdrIOBuffer
~xdrIOBuffer()
Destructor.
Definition xdrIOBuffer.cpp:93
ASSA::xdrIOBuffer::m_state
state_t m_state
Object state.
Definition xdrIOBuffer.h:146
ASSA::xdrIOBuffer::str
const char * str() const
Return pointer to the first byte of xdrIOBuffer.
Definition xdrIOBuffer.h:185
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::m_buf
char * m_buf
Buffer.
Definition xdrIOBuffer.h:137
ASSA::xdrIOBuffer::get_state
string get_state() const
Give verbal interpretation of object's state.
Definition xdrIOBuffer.cpp:210
ASSA::xdrIOBuffer::operator=
xdrIOBuffer & operator=(const xdrIOBuffer &rhs_)
Assign operator.
Definition xdrIOBuffer.cpp:102
ASSA::xdrIOBuffer::state_t
state_t
Definition xdrIOBuffer.h:60
ASSA::xdrIOBuffer::waiting
@ waiting
Definition xdrIOBuffer.h:61
ASSA::xdrIOBuffer::xmitted
@ xmitted
Definition xdrIOBuffer.h:62
ASSA::xdrIOBuffer::parsed
@ parsed
Definition xdrIOBuffer.h:63
ASSA::xdrIOBuffer::error
@ error
Definition xdrIOBuffer.h:64
ASSA::xdrIOBuffer::dump
void dump() const
Dump object's internal state to the log file.
Definition xdrIOBuffer.cpp:225
ASSA::xdrIOBuffer::buffer_size
int buffer_size() const
Return buffer (maximum expected/allowable) size.
Definition xdrIOBuffer.h:178
ASSA
Definition Acceptor.h:40
ASSA::XDRBUFTRACE
@ XDRBUFTRACE
Extended xdrIOBuffer messages
Definition LogMask.h:44