A single class to handle both reading and writing on a port forwarder for the ncs program.
Public Methods
-
void setAllset( fd_set* newAllset )
- Assign pointer to the file descriptor set.
-
void setMaxDescriptor( int* newMaxDescriptor )
- Assign pointer to the maximum value of allocated file desriptors.
-
int setOutputFormat( int newFormat )
- Change the format used to output data to readers
-
int setInputFormat( int format )
- Change the format used receive input data from writer(s?)
-
void setName( char* newName )
- Changes name to new Name while handling memory allocation.
-
int checkName( char* compareName )
- Determine if a given name matches the name on this connection
-
int addReader( int sd, int format=0, int verbose=0 )
- Insert a client that will be sent data as it is received.
-
int addWriter( int sd, int format=0, int verbose=0 )
- Insert a client that will put data onto the data queue(s).
-
void processReaders( fd_set &active )
- Visit each reader and send it the next item from the appropriate data queue.
-
void processWriters( fd_set &active )
- Visit the first writer and receive data or remove it from the list of writers if it has disconnected.
-
int parse()
- Separate data read from the writer into packets.
-
int append( char* buffer, int nread )
- After data has been collected from the writer, it is added to a block of pending data waiting to be parsed.
-
void queueData( char* buffer, int count )
- After a block of actual data has been separated from the block of pending data, it is added to the data queues in preparation for when readers request it.
-
void asciiToBinary( char* buffer, int count )
- If the data received is in ascii, it needs to be converted before any binary readers can receive it.
-
void binaryToAscii( char* buffer, int count )
- If the data received is in binary, it needs to be converted before any ascii readers can receive it.
-
void process( fd_set &active )
- Single function for the main server program to call that will go to process the reader and writer clients.
-
int empty()
- Determine if any readers or writers are connected.
-
void reset()
- Diconnects all readers and writers and clears all data queues
-
static void setPendingReads( int flag )
- Allows the flag that indicates that a reader in any connection object is waiting (and more data is on the queue for it) to be set.
-
static int pendingReadsAndClear()
- Returns whether readers in any connection object are waiting and more data is on the queue, then clears the flag.
-
static int pendingReads()
- Returns whether readers in any connection object are waiting for more data and that data is on the queue
-
char* peek()
- Peek at first item without removing it from the queue.
-
void setVerbose( int flag )
- Sets flag so that when activity occurs on this connection, messages will be sent to the stderr stream or those messages will be suppressed.
-
int giveReaderHeaderInfo( int sd )
- Before a constant binary reader can get data, it needs to know how many elements there are, and the size of each element.
-
int getWriterHeaderInfo( int sd )
- When a constant binary writer connects, it will send the number of elements and the size of those elements.
Documentation
A single class to handle both reading and writing on a port forwarder
for the ncs program. This should not require port numbers, but instead
only depend of socket descriptors
- void setAllset( fd_set* newAllset )
-
Assign pointer to the file descriptor set. This will allow new clients
to be included in the "select" system call.
- Parameters:
- newAllset - Memory location of the file descriptor set.
- void setMaxDescriptor( int* newMaxDescriptor )
-
Assign pointer to the maximum value of allocated file desriptors. When
the "select" call is made, it will only check file descriptors up to a
certain number. If a client connects, and is given a higher number than the
current maximum, then that maximium must be updated so that any new clients are included
in the "select" system call.
- Parameters:
- newMaxDesriptor - Memory address where the current maximum file descriptor is stored.
- int setOutputFormat( int newFormat )
-
Change the format used to output data to readers
- int setInputFormat( int format )
-
Change the format used receive input data from writer(s?)
- void setName( char* newName )
-
Changes name to new Name while handling memory allocation. When a client is searching
for the correct Connection object to connect to, it uses the name to identify the
Connection. NCS creates a name by combining the Brain type, the Brain job, and the
report/stimulus filename into one word (with no separator). The only exception is
the Brain command connection which only uses the Brain type and Brain job to
construct a name.
- Parameters:
- newName - A character string to be duplicated.
- int checkName( char* compareName )
-
Determine if a given name matches the name on this connection
- Parameters:
- compareName - The name to compare with
- Returns:
- 1 on match, 0 on no match, -1 on error
- int addReader( int sd, int format=0, int verbose=0 )
-
Insert a client that will be sent data as it is received.
- Parameters:
- sd - The socket Descriptor of the new client
- format 0 for ascii (default), 1 for binary, 2 for constant binary
- verbose 0 for no output (default), 1 for output
- int addWriter( int sd, int format=0, int verbose=0 )
-
Insert a client that will put data onto the data queue(s). Note - only the
first writer will be allowed to contribute data. Any other writers will be
added to the list, but will not be read from until the first writer disconnects
and the next writer advances to the front of the list.
- Parameters:
- sd - The socket Descriptor of the new client
- format 0 for ascii (default), 1 for binary, 2 for constant binary
- verbose 0 for no output (default), 1 for output
- void processReaders( fd_set &active )
-
Visit each reader and send it the next item from the appropriate data queue. That
is, readers requesting ascii data will receive data in ascii format, binary readers
will receive the data in binary format.
- Parameters:
- active - The set of file descriptor that are active. If a reader has activated
the file decriptor set, it indicates that the reader has disconnected and needs to
be removed.
- void processWriters( fd_set &active )
-
Visit the first writer and receive data or remove it from the list of writers if it
has disconnected.
- Parameters:
- active - The set of file descriptor that are active.
- int parse()
-
Separate data read from the writer into packets. Data received from the writer
should be in the form: number separator data. data is the actual data that should
be added to the queue, number is the length of just the data, and separator is a white
space character including space (' '), newline ('\n'), tab ('\t'), or null ('\0').
Example: 5 0.346
- int append( char* buffer, int nread )
-
After data has been collected from the writer, it is added to a block of pending
data waiting to be parsed.
- Parameters:
- buffer - The data read from the writer
nread - The number of bytes read from the writer
- void queueData( char* buffer, int count )
-
After a block of actual data has been separated from the block of pending data, it
is added to the data queues in preparation for when readers request it.
- Parameters:
- buffer - Pointer to parsed data
count - Number of bytes in data
- void asciiToBinary( char* buffer, int count )
-
If the data received is in ascii, it needs to be converted before any binary readers
can receive it.
- Parameters:
- buffer - Pointer to parsed data
count - Number of bytes in data.
- void binaryToAscii( char* buffer, int count )
-
If the data received is in binary, it needs to be converted before any ascii readers
can receive it.
- Parameters:
- buffer - Pointer to parsed data
count - Number of bytes in data
- void process( fd_set &active )
-
Single function for the main server program to call that will go to process
the reader and writer clients.
- Parameters:
- active - Set of active file descriptors to check against the client file descriptors
- int empty()
-
Determine if any readers or writers are connected.
- Returns:
- 1 if there is at least one reader or writer, otherwise 0.
- void reset()
-
Diconnects all readers and writers and clears all data queues
- static void setPendingReads( int flag )
-
Allows the flag that indicates that a reader in any connection
object is waiting (and more data is on the queue for it) to be
set.
- Parameters:
- flag - Value to set the pending reads flag to.
- static int pendingReadsAndClear()
-
Returns whether readers in any connection object are waiting and
more data is on the queue, then clears the flag.
- Returns:
- 1 if readers waiting, 0 if not
- static int pendingReads()
-
Returns whether readers in any connection object are waiting for
more data and that data is on the queue
- Returns:
- 1 if readers are waiting, 0 if not
- char* peek()
-
Peek at first item without removing it from the queue.
- Returns:
- pointer to first item in the ascii data queue.
- void setVerbose( int flag )
-
Sets flag so that when activity occurs on this connection, messages will
be sent to the stderr stream or those messages will be suppressed.
- Parameters:
- flag - 0 to deactive the verbose feature, 1 to active it
- int giveReaderHeaderInfo( int sd )
-
Before a constant binary reader can get data, it needs to know how many elements there are,
and the size of each element. When that information is available (i.e. a writer has
connected ) it will be sent once. This function will be called if a reader connects, and
a writer has connected previously with the information, or a writer connects, and a reader
is waiting for this information
- Parameters:
- sd - the socket the reader will use
- Returns:
- 0 on success, -1 on failure
- int getWriterHeaderInfo( int sd )
-
When a constant binary writer connects, it will send the number of elements and the size of
those elements.
- Parameters:
- sd - The socket the writer will use
- Returns:
- 0 on success, -1 on failure
- This class has no child classes.
Alphabetic index HTML hierarchy of classes or Java
This page was generated with the help of DOC++.