QFileDescriptor Class Reference
[Networking]

Inheritance diagram for QFileDescriptor:

QListeningSocket

List of all members.


Detailed Description

base class for server side network communication

Author:
Marco Pallavicini

Sergio Di Domizio This class reads commands from a socket, executes them using the appropriate QCommand object and writes error or answer message to the socket.
A valid network command is an arbitrary sequence of characters terminating with a newline (\n) or carriage return (\r) character and whose length in bytes does not exceed MAX_COMMAND_LEN.
A command can contain the special characters used as delimiters (\n and \r), provided that they are escaped.
After receiving a command, this object unescapes the delimiters before forwarding it to the command handler objects.
Similarly, this class escapes possible delimiters contained in the answer/error message returned by the command handlers before writing it back to the socket.


Public Member Functions

 QFileDescriptor ()
 default ctor
 QFileDescriptor (int fds)
 ctor with file descriptor
virtual ~QFileDescriptor ()
 dtor
int FileDescriptor () const
 get file descriptor handled by this object
virtual int HandleCommand (QDescriptorList &descrList)
 handle network command
void SetNext (QFileDescriptor *Next)
 set pointer to next file descriptor in QFileDescriptorList
QFileDescriptorNext () const
 get pointer to next file descriptor in QFileDescriptorList
virtual int Write (const char *message) const
 wrapper for write() syscall
virtual int Write (const char *message, size_t msgSize) const
 wrapper for write() syscall
virtual int Read (char *buff, int max_ch) const
 wrapper for read() syscall

Protected Member Functions

void SetFileDescriptor (int fds)
 set file descriptor associated to this object
char * Buffer ()
 return buffer containing data read from network

Private Member Functions

bool FindCompleteCommand ()
 search buffer for end of command (EOC) character (\r or \n)
int FillBuffer ()
 reads all avaliable data from network and stores it into buffer by calling Read().
void DoParse (const char *Cmd)
 parse and execute requested command and write answer or error to socket

Private Attributes

int fFds
QFileDescriptorfNext
char * fBuffer
int fNextChar
int fNlOffset

Member Function Documentation

int QFileDescriptor::HandleCommand ( QDescriptorList descrList  )  [virtual]

handle network command

Parameters:
descrList descriptor list this fd belogns to
Returns:
0 on success, -1 if client closed connection or errno in case of any other error.

Reimplemented in QListeningSocket.

References fBuffer, FillBuffer(), FindCompleteCommand(), fNextChar, fNlOffset, QCommandHandler::HandleCommand(), and Write().

int QFileDescriptor::Write ( const char *  message  )  const [virtual]

wrapper for write() syscall

Parameters:
message text to be written to the socket
Returns:
number of written bytes or -1 in case of error. On error errno is set one of the error values described in man (2) write.
This method calls Write(char*, size_t) using strlen(message) as a second argument

Referenced by HandleCommand().

int QFileDescriptor::Write ( const char *  message,
size_t  msgSize 
) const [virtual]

wrapper for write() syscall

Parameters:
message text to be written to the socket, including the terminating command delimiter (\n or \r)
Returns:
number of written bytes or -1 in case of error. On error errno is set one of the error values described in man (2) write.

References FileDescriptor().

int QFileDescriptor::Read ( char *  buff,
int  max_ch 
) const [virtual]

wrapper for read() syscall

Returns:
number of read bytes (0 meand end of file) or -1 in case of error. On error errno is set one of the error values described in man (2) read.

References FileDescriptor().

Referenced by FillBuffer().

bool QFileDescriptor::FindCompleteCommand ( void   )  [private]

search buffer for end of command (EOC) character (\r or \n)

Returns:
1 if EOC has been found, 0 otherwise
When returning 1, this method also updates fNlOffset

References fBuffer, fNextChar, and fNlOffset.

Referenced by HandleCommand().

int QFileDescriptor::FillBuffer (  )  [private]

reads all avaliable data from network and stores it into buffer by calling Read().

Returns:
0 on success, -1 if client closed connection (EOF found on data stream), -2 if MAX_COMMAND_LEN has been reached or errno if Read() fails
On success this method also updates fNextChar.

References fBuffer, fNextChar, MAX_COMMAND_LEN, and Read().

Referenced by HandleCommand().

void QFileDescriptor::DoParse ( const char *  Cmd  )  [private]

parse and execute requested command and write answer or error to socket

Command parsing and execution is performed using classes in the parser package.


Member Data Documentation

int QFileDescriptor::fFds [private]

file descriptor

Referenced by FileDescriptor(), SetFileDescriptor(), and ~QFileDescriptor().

linked list (one way)

Referenced by Next(), and SetNext().

char* QFileDescriptor::fBuffer [private]

buffer containing data read from socket

Referenced by Buffer(), FillBuffer(), FindCompleteCommand(), HandleCommand(), QFileDescriptor(), and ~QFileDescriptor().

index of first free char in fBuffer

Referenced by FillBuffer(), FindCompleteCommand(), and HandleCommand().

size of the last received command including terminating character (\n or \r)

Referenced by FindCompleteCommand(), and HandleCommand().


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

Generated on Tue Nov 16 10:50:05 2010 for CUORE Software by  doxygen 1.5.6