file Class Reference

An input/output channel. More...

#include <file.h>

Inheritance diagram for file:
Inheritance graph
[legend]
Collaboration diagram for file:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 file (const string &inpath)
bool openread (const string &fn)
bool openread (int fd)
bool openwrite (const string &fn, int mode=0644)
bool openwrite (int fd)
bool openappend (const string &fn, int mode=0644)
void close (void)
stringgets (int maxlinesize=1024)
bool waitforline (string &into, int timeout_ms, int maxlinesize=1024)
bool readuntil (string &into, const string &watchfor, unsigned int size, int tmout)
int readbuffer (size_t, unsigned int tmout=0)
stringread (size_t sz)
stringread (size_t sz, int timeout_ms)
bool writeln (const string &str)
bool puts (const string &s)
bool puts (const char *data, size_t sz)
int tryputs (const char *str, size_t sz, unsigned int tmout=0)
bool printf (const char *,...)
void flush (void)
bool eof (void)
off_t pos (void)
 operator bool (void)
const stringerror (void)
unsigned int errorcode (void)
stringvisitchild (int index)

Public Attributes

ringbuffer buffer
iocodeccodec
int filno

Protected Attributes

bool feof
bool nonblocking
unsigned int errcode
string err

Detailed Description

An input/output channel.

Type Constraints

Constructor & Destructor Documentation

file::file ( const string inpath  )  [inline]

Constructor with explicit path.

Opens a file for reading (or writing)

Parameters:
inpath The disk file to open. If this starts with a '<', the file is opened for reading. If it starts with a '>', it is opened for writing (in both cases the first character is stripped). In other cases the file will be opened for reading.

References codec, errcode, feof, filno, string::mid(), nonblocking, openread(), and openwrite().

Here is the call graph for this function:


Member Function Documentation

bool file::eof ( void   ) 
string * file::gets ( int  maxlinesize = 1024  ) 

Read a string terminated by a newline.

Parameters:
maxlinesize Set maximum size of a line.
Returns:
New string object with data.
Exceptions:
endOfFileException End of file reached.
fileNotOpenException File is not open.
fileCodecException Codec failure.
fileReadException File read error.
EX_SSL_BUFFER_SNAFU Error in sslcodec buffer.
EX_SSL_PROTOCOL_ERROR Error in sslcodec protocol.
EX_SSL_CLIENT_ALERT Unhandled sslcodec client alert.

References ringbuffer::add(), iocodec::addinput(), ringbuffer::backlog(), buffer, codec, string::crop(), iocodec::doneoutput(), err, errcode, iocodec::error(), feof, iocodec::fetchinput(), filno, ringbuffer::hasline(), nonblocking, iocodec::peekoutput(), string::printf(), ringbuffer::read(), read(), defaults::sz::file::readbuf, ringbuffer::readline(), ringbuffer::room(), string::str(), and string::strlen().

Referenced by daemon::daemonize(), smtpsocket::dosmtp(), process::gets(), httpdfileshare::httpdfileshare(), value::load(), value::loadcsv(), value::loadini(), value::loadinitree(), smtpworker::run(), httpdworker::run(), and visitchild().

Here is the call graph for this function:

bool file::openappend ( const string fn,
int  mode = 0644 
)

Open a disk file for appending.

Parameters:
fn Name (and path) of the file.
mode Unix permissio bits.
Returns:
Result, true if open succeeded.

References buffer, feof, filno, ringbuffer::flush(), string::str(), string::strlen(), and filesystem::transw().

Referenced by daemon::addlogtarget(), httpdlogger::httpdlogger(), and logthread::run().

Here is the call graph for this function:

bool file::openread ( int  fd  ) 

Open a unix filedecriptor for reading.

Parameters:
fd The filedescriptor.
Returns:
Result, true if open succeeded.

References buffer, codec, feof, filno, ringbuffer::flush(), and iocodec::setup().

Here is the call graph for this function:

bool file::openread ( const string fn  ) 
bool file::openwrite ( int  fd  ) 

Open a unix filedescriptor for writing.

Parameters:
fd The filedescriptor.
Returns:
Result, true if open succeeded.

References buffer, close(), codec, feof, filno, ringbuffer::flush(), iocodec::peekoutput(), iocodec::setup(), string::str(), and string::strlen().

Here is the call graph for this function:

bool file::openwrite ( const string fn,
int  mode = 0644 
)

Open a disk file for writing.

Parameters:
fn Name (and path) of the file.
mode Unix permissio bits.
Returns:
Result, true if open succeeded.

References buffer, close(), codec, feof, filno, ringbuffer::flush(), iocodec::peekoutput(), iocodec::setup(), string::str(), string::strlen(), and filesystem::transw().

Referenced by application::application(), filesystem::cp(), file(), process::init(), value::save(), filesystem::save(), value::savecsv(), and daemon::writepid().

Here is the call graph for this function:

file::operator bool ( void   )  [inline]

Bool cast.

Casts to true if the file is open.

References filno.

off_t file::pos ( void   ) 

Position.

Returns:
The current position in a disk file that is open for writing/reading.

References filno.

Referenced by logthread::run().

bool file::printf ( const char *  fmtx,
  ... 
)

A libc-style printf.

Returns:
Status, true for success.
Exceptions:
EX_SSL_NO_HANDSHAKE No sslcodec handshake done.
EX_SSL_BUFFER_SNAFU Error in sslcodec buffer.

References string::crop(), puts(), string::strcat(), and string::strlen().

Referenced by daemon::daemonize(), httpd::handle(), systemprocess::main(), cgi::main(), application::main(), value::print(), smtpworker::run(), value::savecsv(), cgi::sendpage(), and daemon::writepid().

Here is the call graph for this function:

bool file::puts ( const char *  data,
size_t  sz 
)

Write a data block.

Parameters:
data Pointer to the data.
sz Size of teh data block.
Returns:
Status, true for success.
Exceptions:
EX_SSL_NO_HANDSHAKE No sslcodec handshake done.
EX_SSL_BUFFER_SNAFU Error in sslcodec buffer.

References iocodec::addoutput(), codec, iocodec::doneoutput(), feof, filno, nonblocking, iocodec::peekoutput(), string::str(), and string::strlen().

Here is the call graph for this function:

bool file::puts ( const string s  ) 
string * file::read ( size_t  sz,
int  timeout_ms 
)

Nonblocking read.

Returns a string object with the data.

Parameters:
sz Number of bytes to read.
timeout_ms Timeout in milliseconds.
Returns:
New string object.
Exceptions:
endOfFileException End of file reached.
fileNotOpenException File not open.
fileReadException File read error.
EX_SSL_BUFFER_SNAFU Error in sslcodec buffer.
EX_SSL_PROTOCOL_ERROR Error in sslcodec protocol.
EX_SSL_CLIENT_ALERT Unhandled sslcodec client alert.

References ringbuffer::add(), iocodec::addinput(), ringbuffer::backlog(), buffer, codec, string::crop(), iocodec::doneoutput(), err, errcode, feof, iocodec::fetchinput(), filno, nonblocking, iocodec::peekoutput(), string::printf(), read(), ringbuffer::read(), defaults::sz::file::readbuf, ringbuffer::room(), string::str(), and string::strlen().

Here is the call graph for this function:

string * file::read ( size_t  sz  ) 

Blocking read.

Returns a string object with the data.

Parameters:
sz Number of bytes to read.
Returns:
New string object.
Exceptions:
endOfFileException End of file reached.
fileNotOpenException File not open.
fileReadException File read error.
EX_SSL_BUFFER_SNAFU Error in sslcodec buffer.
EX_SSL_PROTOCOL_ERROR Error in sslcodec protocol.
EX_SSL_CLIENT_ALERT Unhandled sslcodec client alert.

References ringbuffer::add(), iocodec::addinput(), ringbuffer::backlog(), buffer, codec, string::crop(), err, errcode, feof, iocodec::fetchinput(), filno, nonblocking, string::printf(), ringbuffer::read(), defaults::sz::file::readbuf, and ringbuffer::room().

Referenced by cgi::cgi(), tcpsocket::connect(), filesystem::cp(), termbuffer::getkey(), gets(), filesystem::load(), process::read(), read(), readbuffer(), httpdworker::run(), tcpsocket::sendfile(), and waitforline().

Here is the call graph for this function:

int file::readbuffer ( size_t  sz,
unsigned int  tmout = 0 
)

Read data into the internal buffer.

Parameters:
sz Number of bytes to read.
tmout Timeout in milliseconds.
Returns:
Number of bytes read.
Exceptions:
endOfFileException End of file reached.
fileNotOpenException File not open.
fileReadException File read error.
EX_SSL_BUFFER_SNAFU Error in sslcodec buffer.
EX_SSL_PROTOCOL_ERROR Error in sslcodec protocol.
EX_SSL_CLIENT_ALERT Unhandled sslcodec client alert.

References ringbuffer::add(), iocodec::addinput(), buffer, codec, string::crop(), err, errcode, feof, iocodec::fetchinput(), filno, nonblocking, string::printf(), read(), and ringbuffer::room().

Referenced by readuntil().

Here is the call graph for this function:

bool file::readuntil ( string into,
const string watchfor,
unsigned int  size,
int  tmout 
)

Keep reading into a string until a specific byte sequence occurs.

Parameters:
into String to append data to.
watchfor Pointer to byte sequence.
size Size of byte sequence.
tmout Timeout in milliseconds.
Returns:
Status, false in case of a timeout condition.

References ringbuffer::backlog(), buffer, ringbuffer::findforward(), ringbuffer::read(), readbuffer(), and string::strcat().

Here is the call graph for this function:

int file::tryputs ( const char *  str,
size_t  sz,
unsigned int  tmout = 0 
)

Non-blocking puts.

Parameters:
str Pointer to the data.
sz Size of the data to be written.
tmout Timeout in milliseconds.
Returns:
Number of bytes written.
Exceptions:
EX_SSL_NO_HANDSHAKE No sslcodec handshake done.
EX_SSL_BUFFER_SNAFU Error in sslcodec buffer.

References iocodec::addoutput(), iocodec::canoutput(), codec, iocodec::doneoutput(), feof, filno, nonblocking, iocodec::peekoutput(), string::str(), and string::strlen().

Here is the call graph for this function:

bool file::waitforline ( string into,
int  timeout_ms,
int  maxlinesize = 1024 
)

Wait for a string terminated by a newline.

Parameters:
into String to append the line to.
timeout_ms Timeout in milliseconds.
maxlinesize Maximum size of a line.
Returns:
Status, false in case of a timeout condition.
Exceptions:
endOfFileException End of file reached.
fileNotOpenException File not open.
fileReadException File read error.
EX_SSL_BUFFER_SNAFU Error in sslcodec buffer.
EX_SSL_PROTOCOL_ERROR Error in sslcodec protocol.
EX_SSL_CLIENT_ALERT Unhandled sslcodec client alert.

References ringbuffer::add(), iocodec::addinput(), buffer, codec, string::crop(), err, errcode, feof, iocodec::fetchinput(), filno, ringbuffer::hasline(), nonblocking, string::printf(), ringbuffer::read(), read(), ringbuffer::readline(), and ringbuffer::room().

Here is the call graph for this function:

bool file::writeln ( const string str  ) 

Write a string followed by a newline.

Parameters:
str The string to write.
Returns:
Status, true for success.

References puts(), string::str(), and string::strlen().

Referenced by daemon::daemonize(), daemon::delayedexiterror(), daemon::delayedexitok(), daemon::log(), logthread::run(), and termbuffer::writeconsole().

Here is the call graph for this function:


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

Generated on Sun Feb 28 10:35:40 2010 for GRACE by  doxygen 1.6.1