Argo  1.0
A C++ library for handling JSON.
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
argo::fd_reader Class Reference

A derived class of reader that reads from POSIX file descriptors. More...

#include <fd_reader.hpp>

Inheritance diagram for argo::fd_reader:
argo::reader

Public Member Functions

 fd_reader (int fd, int max_message_length, bool block_read)
 
- Public Member Functions inherited from argo::reader
 reader (size_t max_message_length, bool block_read)
 
virtual int next ()
 Get the next character from the reader. More...
 
virtual void put_back (int c)
 Put back a character so that it is returned by the next call to next().
 
size_t get_byte_index () const
 Get the current byte index in the input.
 
void reset_byte_index ()
 Reset the byte index at the start of parsing a messege.
 

Protected Member Functions

virtual int read_next_char ()
 
virtual bool read_next_block ()
 
- Protected Member Functions inherited from argo::reader
int read_next_char_from_block ()
 When in block read mode, get the next available character.
 

Protected Attributes

int m_fd
 Underlying POSIX file descriptor.
 
- Protected Attributes inherited from argo::reader
int m_put_back
 Character last put back. If equal to no_put_back then none was.
 
size_t m_byte_index
 Total number of characters read.
 
size_t m_max_message_length
 Maximum length of a message.
 
bool m_block_read
 Whether to read in blocks or one byte at a time.
 
unsigned char m_block [block_size]
 If we're reading blocks, the block data.
 
int m_block_num_bytes
 If we're reading blocks, the number of bytes in the current block.
 
int m_block_index
 If we're reading blocks, the index into the current block.
 

Additional Inherited Members

- Static Public Attributes inherited from argo::reader
static const int block_size = 8192
 Amount of data to read at once when in block read mode.
 
- Static Protected Attributes inherited from argo::reader
static const int no_put_back = 1000
 Special character value indicating that no character has been put back.
 

Detailed Description

A derived class of reader that reads from POSIX file descriptors.

Definition at line 33 of file fd_reader.hpp.

Constructor & Destructor Documentation

fd_reader::fd_reader ( int  fd,
int  max_message_length,
bool  block_read 
)

Constructor.

Parameters
fdPOSIX stream file descriptor. The instance does not take ownership of the open file and it is up to the calling code to close it when done.
max_message_lengthLongest message that can be read.
block_readWhether to read in blocks or one byte at a time.

Definition at line 35 of file fd_reader.cpp.

Member Function Documentation

bool fd_reader::read_next_block ( )
protectedvirtual

Read the next block of data up to block_size bytes.

Returns
true if some data was read, false if EOF.
Exceptions
json_io_errorif the read failed for some reason other than EOF.

Implements argo::reader.

Definition at line 63 of file fd_reader.cpp.

int fd_reader::read_next_char ( )
protectedvirtual

Read a character from the file descriptor using the read() system call.

Exceptions
json_io_exceptionThrown in the event the read() call fails.

Implements argo::reader.

Definition at line 41 of file fd_reader.cpp.


The documentation for this class was generated from the following files: