VCF::TCPSocketInputStream Class Reference
An input stream class used for reading data from a TCP socket. More...
#include <vcf/NetworkKit/Socket.h>
Inheritance diagram for VCF::TCPSocketInputStream:

Public Member Functions | |
| TCPSocketInputStream (TCPSocket &socket) | |
| virtual void | seek (const uint64 &offset, const SeekType &offsetFrom) |
| Seeking is not permitted! | |
| virtual uint64 | getSize () |
| returns the size of the stream. | |
| virtual uchar * | getBuffer () |
| Throws an exception - this is not permitted. | |
| virtual uint64 | getCurrentSeekPos () |
| Throws an exception - this is not permitted. | |
| virtual bool | isEOS () |
| virtual uint64 | read (unsigned char *bytesToRead, uint64 sizeOfBytes) |
| Attempts to read sizeOfBytes from the TCP socket associated with this stream. | |
Protected Attributes | |
| uint64 | totalBytesRecvd_ |
| Socket * | socket_ |
Detailed Description
An input stream class used for reading data from a TCP socket.The class must be used in conjunction with a valid socket instance, you cannot create in instance otherwise. Not all of the InputStream class's methods can be implemented, for example, the seek method is meaningless in this context, and calling it will result in a RuntimeException being thrown. The only method that makes sense to call is the read() method.
- An example of how to use the class might look like this:
Socket* socket = \\get valid socket instance from somewhere...
SocketInputStream sis(*socket);
uchar tmp[256];
while ( true ) {
socket->selectFor( Socket::SelectWaitForever, Socket::ssReadable );
do {
try {
uint64 err = sis.read( tmp, sizeof(tmp) );
if ( err == 0 ) {
break;
}
else {
//do something with the data stored in the
//tmp buffer...
}
}
catch ( BasicException& ) {
//exit the loop!
break;
}
} while( socket->pending() && socket->isReadable() ) ;
if ( socket->isClosed() || socket->hasError() ) {
//exit the loop if we detect problems or the socket has
//been closed...
break;
}
}
- See also:
- Socket::selectFor
Constructor & Destructor Documentation
|
|
|
Member Function Documentation
|
|
Throws an exception - this is not permitted.
Implements VCF::Stream. |
|
|
Throws an exception - this is not permitted.
Implements VCF::Stream. |
|
|
returns the size of the stream. The size represents the number of bytes that have been written, or read to/from the stream Implements VCF::Stream. |
|
|
Implements VCF::InputStream. |
|
||||||||||||
|
Attempts to read sizeOfBytes from the TCP socket associated with this stream. The method will return the number of bytes read from the socket. The return may be the following:
Implements VCF::InputStream. |
|
||||||||||||
|
Seeking is not permitted!
Implements VCF::Stream. |
Member Data Documentation
|
|
|
|
|
|
The documentation for this class was generated from the following file:
- vcf/NetworkKit/Socket.h
