class Connection

A single class to handle both reading and writing on a port forwarder for the ncs program.

Public Methods

[more]void setAllset( fd_set* newAllset )
Assign pointer to the file descriptor set.
[more]void setMaxDescriptor( int* newMaxDescriptor )
Assign pointer to the maximum value of allocated file desriptors.
[more]int setOutputFormat( int newFormat )
Change the format used to output data to readers
[more]int setInputFormat( int format )
Change the format used receive input data from writer(s?)
[more]void setName( char* newName )
Changes name to new Name while handling memory allocation.
[more]int checkName( char* compareName )
Determine if a given name matches the name on this connection
[more]int addReader( int sd, int format=0, int verbose=0 )
Insert a client that will be sent data as it is received.
[more]int addWriter( int sd, int format=0, int verbose=0 )
Insert a client that will put data onto the data queue(s).
[more]void processReaders( fd_set &active )
Visit each reader and send it the next item from the appropriate data queue.
[more]void processWriters( fd_set &active )
Visit the first writer and receive data or remove it from the list of writers if it has disconnected.
[more]int parse()
Separate data read from the writer into packets.
[more]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.
[more]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.
[more]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.
[more]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.
[more]void process( fd_set &active )
Single function for the main server program to call that will go to process the reader and writer clients.
[more]int empty()
Determine if any readers or writers are connected.
[more]void reset()
Diconnects all readers and writers and clears all data queues
[more]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.
[more]static int pendingReadsAndClear()
Returns whether readers in any connection object are waiting and more data is on the queue, then clears the flag.
[more]static int pendingReads()
Returns whether readers in any connection object are waiting for more data and that data is on the queue
[more]char* peek()
Peek at first item without removing it from the queue.
[more]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.
[more]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.
[more]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
ovoid 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.

ovoid 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.

oint setOutputFormat( int newFormat )
Change the format used to output data to readers

oint setInputFormat( int format )
Change the format used receive input data from writer(s?)

ovoid 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.

oint 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

oint 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

oint 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

ovoid 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.

ovoid 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.

oint 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

oint 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

ovoid 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

ovoid 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.

ovoid 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

ovoid 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

oint empty()
Determine if any readers or writers are connected.
Returns:
1 if there is at least one reader or writer, otherwise 0.

ovoid reset()
Diconnects all readers and writers and clears all data queues

ostatic 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.

ostatic 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

ostatic 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

ochar* peek()
Peek at first item without removing it from the queue.
Returns:
pointer to first item in the ascii data queue.

ovoid 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

oint 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

oint 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++.