oasys::BufferedInput Class Reference

#include <BufferedIO.h>

Inheritance diagram for oasys::BufferedInput:

oasys::Logger List of all members.

Detailed Description

Wrapper class for an IOClient that includes an in-memory buffer for reading and/or writing.

Definition at line 51 of file BufferedIO.h.

Public Member Functions

 BufferedInput (IOClient *client, const char *logbase="/BufferedInput")
 ~BufferedInput ()
int read_line (const char *nl, char **buf, int timeout=-1)
 Read in a line of input, newline characters included.
int read_bytes (size_t len, char **buf, int timeout=-1)
 Read len bytes.
int read_some_bytes (char **buf, int timeout=-1)
 Read some bytes.
char get_char (int timeout=-1)
 Read in a single character from the protocol stream.
bool eof ()
 Returns true if at the end of file.

Private Member Functions

int internal_read (size_t len=0, int timeout_ms=-1)
 Read in len bytes into the buffer.
int find_nl (const char *nl)
 
Returns:
Index of the start of the sequence of the newline character string


Private Attributes

IOClientclient_
StreamBuffer buf_
bool seen_eof_

Static Private Attributes

static const size_t READ_AHEAD = 256
static const size_t MAX_LINE = 4096
 Amount to read when buffer is full.


Constructor & Destructor Documentation

oasys::BufferedInput::BufferedInput ( IOClient client,
const char *  logbase = "/BufferedInput" 
)

Definition at line 54 of file BufferedIO.cc.

oasys::BufferedInput::~BufferedInput (  ) 

Definition at line 61 of file BufferedIO.cc.


Member Function Documentation

int oasys::BufferedInput::read_line ( const char *  nl,
char **  buf,
int  timeout = -1 
)

Read in a line of input, newline characters included.

Parameters:
nl character string that defines a newline
buf output parameter containing a pointer to the buffer with the line, valid until next call to read_line
timeout timeout value for read
Returns:
length of line, including nl characters. <0 on error, 0 on eof.

Definition at line 65 of file BufferedIO.cc.

References buf_, oasys::StreamBuffer::consume(), errno, find_nl(), oasys::StreamBuffer::fullbytes(), internal_read(), log_debug, READ_AHEAD, and oasys::StreamBuffer::start().

Referenced by oasys::SMTP::process_cmd(), and oasys::SMTP::process_response().

int oasys::BufferedInput::read_bytes ( size_t  len,
char **  buf,
int  timeout = -1 
)

Read len bytes.

Blocking until specified amount of bytes is read.

Parameters:
len length to read
buf output parameter containing a pointer to the buffer with the line, valid until next call to read_line
timeout timeout value for read
Returns:
length of segment read. <0 upon error, 0 on eof. Return will only be < len if eof is reached before fully read len bytes.

Definition at line 92 of file BufferedIO.cc.

References ASSERT, buf_, oasys::StreamBuffer::consume(), errno, oasys::StreamBuffer::fullbytes(), internal_read(), log_debug, and oasys::StreamBuffer::start().

int oasys::BufferedInput::read_some_bytes ( char **  buf,
int  timeout = -1 
)

Read some bytes.

Parameters:
buf output parameter containing a pointer to the buffer with the line, valid until next call to read_line
timeout timeout value for read
Returns:
length of segment read. <0 upon error, 0 on eof.

Definition at line 128 of file BufferedIO.cc.

References ASSERT, buf_, oasys::StreamBuffer::consume(), oasys::StreamBuffer::end(), errno, oasys::StreamBuffer::fullbytes(), internal_read(), log_debug, oasys::LOG_ERR, oasys::Logger::logf(), oasys::StreamBuffer::start(), and oasys::StreamBuffer::tailbytes().

char oasys::BufferedInput::get_char ( int  timeout = -1  ) 

Read in a single character from the protocol stream.

Returns 0 if at the end of the stream or error.

Definition at line 163 of file BufferedIO.cc.

References ASSERT, buf_, oasys::StreamBuffer::consume(), errno, oasys::StreamBuffer::fullbytes(), internal_read(), oasys::LOG_ERR, oasys::Logger::logf(), oasys::StreamBuffer::start(), and oasys::StreamBuffer::tailbytes().

bool oasys::BufferedInput::eof (  ) 

Returns true if at the end of file.

Definition at line 186 of file BufferedIO.cc.

References buf_, oasys::StreamBuffer::fullbytes(), and seen_eof_.

int oasys::BufferedInput::internal_read ( size_t  len = 0,
int  timeout_ms = -1 
) [private]

Read in len bytes into the buffer.

If there are enough bytes already present in buf_, no call to read will occur.

Parameters:
len The amount to read
timeout_ms Timeout to the read call. UNIMPLEMENTED
Returns:
Bytes available, can be less than len.

Definition at line 192 of file BufferedIO.cc.

References ASSERT, buf_, client_, oasys::StreamBuffer::end(), errno, oasys::StreamBuffer::fill(), oasys::StreamBuffer::fullbytes(), oasys::IOTIMEOUT, log_debug, oasys::LOG_ERR, oasys::Logger::logf(), oasys::IOClient::read(), oasys::StreamBuffer::reserve(), seen_eof_, oasys::StreamBuffer::start(), oasys::StreamBuffer::tailbytes(), and oasys::IOClient::timeout_read().

Referenced by get_char(), read_bytes(), read_line(), and read_some_bytes().

int oasys::BufferedInput::find_nl ( const char *  nl  )  [private]

Returns:
Index of the start of the sequence of the newline character string

Definition at line 252 of file BufferedIO.cc.

References buf_, oasys::StreamBuffer::fullbytes(), and oasys::StreamBuffer::start().

Referenced by read_line().


Member Data Documentation

IOClient* oasys::BufferedInput::client_ [private]

Definition at line 123 of file BufferedIO.h.

Referenced by internal_read().

StreamBuffer oasys::BufferedInput::buf_ [private]

Definition at line 124 of file BufferedIO.h.

Referenced by eof(), find_nl(), get_char(), internal_read(), read_bytes(), read_line(), and read_some_bytes().

bool oasys::BufferedInput::seen_eof_ [private]

Definition at line 126 of file BufferedIO.h.

Referenced by eof(), and internal_read().

const size_t oasys::BufferedInput::READ_AHEAD = 256 [static, private]

Definition at line 128 of file BufferedIO.h.

Referenced by read_line().

const size_t oasys::BufferedInput::MAX_LINE = 4096 [static, private]

Amount to read when buffer is full.

Definition at line 129 of file BufferedIO.h.


The documentation for this class was generated from the following files:
Generated on Fri Dec 22 14:48:06 2006 for DTN Reference Implementation by  doxygen 1.5.1