Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

CharInBuffer.cpp File Reference

#include <errno.h>
#include "assa/CharInBuffer.h"
#include "assa/MemDump.h"
#include "assa/Logger.h"

Go to the source code of this file.

Namespaces

namespace  ASSA

Functions

Socketoperator>> (Socket &s_, CharInBuffer &b_)
 Read bytes from Socket stream until either record delimiter is detected, or EOF occured, or Socket stream is exhausted.


Function Documentation

Socket& ASSA::operator>> ASSA::Socket s_,
ASSA::CharInBuffer b_
 

Read bytes from Socket stream until either record delimiter is detected, or EOF occured, or Socket stream is exhausted.

If match, bite off delimiter and set the state to complete. If not, continue reading till either there is no more characters to read, or Socket error (Fail or EOF), or buffer overflow. If overflow occurs, set the state to 'error' and terminate.

Definition at line 80 of file CharInBuffer.cpp.

References ASSA::CHARINBUF, ASSA::CharInBuffer::chop(), ASSA::CharInBuffer::complete, DL, ASSA::CharInBuffer::error, ASSA::CharInBuffer::m_buffer, ASSA::CharInBuffer::m_delimiter, ASSA::CharInBuffer::m_max_size, ASSA::CharInBuffer::m_state, ASSA::Socket::read(), ASSA::CharInBuffer::state(), ASSA::CharInBuffer::state_name(), trace_with_mask, and ASSA::CharInBuffer::waiting.

00081 {
00082     trace_with_mask ("Socket >> CharInBuffer", CHARINBUF);
00083     register char c;
00084 
00085     if (b_.state () != CharInBuffer::waiting) {
00086         DL((CHARINBUF,"Wrong state %s\n", b_.state_name (b_.state ())));
00087         return s_;
00088     }
00089 
00090     while (s_.read (&c, 1) == 1) 
00091     {
00092         b_.m_buffer += c;
00093 
00094         if (b_.m_buffer.size() < b_.m_delimiter.size()) { // Bug # 1252926
00095             continue;
00096         }
00097 
00098         if (b_.m_buffer.substr (
00099                 b_.m_buffer.size ()-b_.m_delimiter.size ()) == b_.m_delimiter) 
00100         {
00101             b_.chop ();
00102             b_.m_state = CharInBuffer::complete;
00103             return s_;
00104         }
00105 
00106         if (b_.m_buffer.length () >= b_.m_max_size) {
00107             b_.m_state = CharInBuffer::error;
00108             break;
00109         }
00110     }
00111 
00112     if (!s_) {                  // EOF or error
00113         b_.state (CharInBuffer::error);
00114     }
00115     
00116     return s_;
00117 }


Generated on Mon Mar 26 22:47:35 2007 for libassa by  doxygen 1.4.2