Gnash  0.8.10
Public Member Functions
gnash::Socket Class Reference

A simple IOChannel subclass for reading and writing sockets. More...

#include <Socket.h>

Inheritance diagram for gnash::Socket:
gnash::IOChannel

List of all members.

Public Member Functions

 Socket ()
 Create a non-connected socket.
virtual ~Socket ()
bool connect (const std::string &hostname, boost::uint16_t port)
 Initiate a connection.
void close ()
 Close the Socket.
bool connected () const
 Whether a connection attempt is complete.
virtual bool bad () const
 True if the Socket is in an error condition.
virtual std::streamsize read (void *dst, std::streamsize num)
 Read exactly the given number of bytes from the Socket or none at all.
virtual std::streamsize readNonBlocking (void *dst, std::streamsize num)
 Read up to the given number of bytes from the Socket.
virtual std::streamsize write (const void *src, std::streamsize num)
 Write the given number of bytes to the stream.
virtual std::streampos tell () const
 Return current stream position.
virtual bool seek (std::streampos p)
 Seek to the specified position.
virtual void go_to_end ()
 Seek to the end of the stream.
virtual bool eof () const
 Return true if the end of the stream has been reached.

Detailed Description

A simple IOChannel subclass for reading and writing sockets.

The Socket class will give you years of satisfaction provided you observe the following points: 1. A socket is active only when both connected() and not bad(). 2. The only accurate way of determining an error is to check bad(). 3. read() and write() should not be called until connected() is true.


Constructor & Destructor Documentation

gnash::Socket::Socket ( )

Create a non-connected socket.

virtual gnash::Socket::~Socket ( ) [inline, virtual]

Member Function Documentation

virtual bool gnash::Socket::bad ( ) const [inline, virtual]

True if the Socket is in an error condition.

An error condition is fatal and can only be reset when the Socket is closed. Any read or write failure other than EAGAIN or EWOULDBLOCK causes a fatal error.

Implements gnash::IOChannel.

References _error.

Referenced by gnash::rtmp::RTMP::readSocket(), readNonBlocking(), write(), and eof().

void gnash::Socket::close ( )

Close the Socket.

A closed Socket is in a state where another connection attempt can be made. Any errors are reset.

References _error.

Referenced by gnash::rtmp::RTMP::close().

bool gnash::Socket::connect ( const std::string &  hostname,
boost::uint16_t  port 
)

Initiate a connection.

A return of true does not mean the connection has succeeded, only that it did not fail. The connection attempt is only complete when connected() returns true.

Returns:
false if the connection fails. In this case, the Socket is still in a closed state and is ready for a new connection attempt. Otherwise true.

References _, assert, _error, and gnash::key::a.

Referenced by gnash::rtmp::RTMP::connect().

bool gnash::Socket::connected ( ) const

Whether a connection attempt is complete.

This is true as soon as the socket is ready for reading and writing. But beware! This function may still return true if the Socket is in error condition. Always check bad() if you care about this.

References _error, and _.

Referenced by gnash::rtmp::RTMP::readSocket().

bool gnash::Socket::eof ( ) const [virtual]

Return true if the end of the stream has been reached.

EOF is when remote end closed the connection and we have no more cached data to read

Implements gnash::IOChannel.

References bad().

Referenced by gnash::rtmp::RTMP::readSocket().

void gnash::Socket::go_to_end ( ) [virtual]

Seek to the end of the stream.

Not Socket.

Implements gnash::IOChannel.

References _.

std::streamsize gnash::Socket::read ( void *  dst,
std::streamsize  num 
) [virtual]

Read exactly the given number of bytes from the Socket or none at all.

Implements gnash::IOChannel.

References _error, and readNonBlocking().

Referenced by gnash::rtmp::RTMP::readSocket().

std::streamsize gnash::Socket::readNonBlocking ( void *  dst,
std::streamsize  num 
) [virtual]

Read up to the given number of bytes from the Socket.

Reimplemented from gnash::IOChannel.

References bad(), _error, gnash::arraySize(), and _cache.

Referenced by read().

bool gnash::Socket::seek ( std::streampos  p) [virtual]

Seek to the specified position.

Meaningless for a Socket.

Implements gnash::IOChannel.

References _.

std::streampos gnash::Socket::tell ( ) const [virtual]

Return current stream position.

Meaningless for a Socket.

Implements gnash::IOChannel.

References _.

std::streamsize gnash::Socket::write ( const void *  src,
std::streamsize  num 
) [virtual]

Write the given number of bytes to the stream.

If you call write() before connected() is true, it may put the Socket into an error condition. Calling write() when the Socket is bad has no effect.

Reimplemented from gnash::IOChannel.

References bad(), and _.

Referenced by gnash::rtmp::RTMP::sendPacket().


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