Gnash
0.8.11dev
|
A simple IOChannel subclass for reading and writing sockets. More...
#include <Socket.h>
Public Member Functions | |
Socket () | |
Create a non-connected socket. More... | |
virtual | ~Socket () |
bool | connect (const std::string &hostname, std::uint16_t port) |
Initiate a connection. More... | |
void | close () |
Close the Socket. More... | |
bool | connected () const |
Whether a connection attempt is complete. More... | |
virtual bool | bad () const |
True if the Socket is in an error condition. More... | |
virtual std::streamsize | read (void *dst, std::streamsize num) |
Read exactly the given number of bytes from the Socket or none at all. More... | |
virtual std::streamsize | readNonBlocking (void *dst, std::streamsize num) |
Read up to the given number of bytes from the Socket. More... | |
virtual std::streamsize | write (const void *src, std::streamsize num) |
Write the given number of bytes to the stream. More... | |
virtual std::streampos | tell () const |
Return current stream position. More... | |
virtual bool | seek (std::streampos p) |
Seek to the specified position. More... | |
virtual void | go_to_end () |
Seek to the end of the stream. More... | |
virtual bool | eof () const |
Return true if the end of the stream has been reached. More... | |
![]() | |
virtual | ~IOChannel () |
std::uint32_t | read_le32 () |
Read a 32-bit word from a little-endian stream. returning it as a native-endian word. More... | |
std::uint16_t | read_le16 () |
Read a 16-bit word from a little-endian stream. More... | |
std::uint8_t | read_byte () |
Read a single byte from the stream. More... | |
int | read_string (char *dst, int max_length) |
Read up to max_length characters, returns the number of characters read, or -1 if the string length is longer than max_length. More... | |
virtual size_t | size () const |
Get the size of the stream (unreliably). More... | |
A simple IOChannel subclass for reading and writing sockets.
The Socket class will give you years of satisfaction provided you observe the following points:
gnash::Socket::Socket | ( | ) |
Create a non-connected socket.
|
inlinevirtual |
|
inlinevirtual |
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.
Referenced by eof(), readNonBlocking(), gnash::rtmp::RTMP::readSocket(), and write().
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.
Referenced by gnash::rtmp::RTMP::close().
bool gnash::Socket::connect | ( | const std::string & | hostname, |
std::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.
References _, gnash::arraySize(), gnash::LogFile::getDefaultInstance(), gnash::log_debug(), and gnash::log_error().
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 gnash::log_debug().
Referenced by gnash::rtmp::RTMP::close(), and gnash::rtmp::RTMP::readSocket().
|
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().
|
virtual |
Seek to the end of the stream.
Not Socket.
Implements gnash::IOChannel.
References _, and gnash::log_error().
|
virtual |
Read exactly the given number of bytes from the Socket or none at all.
Implements gnash::IOChannel.
Referenced by gnash::rtmp::RTMP::close(), and gnash::rtmp::RTMP::readSocket().
|
virtual |
Read up to the given number of bytes from the Socket.
Reimplemented from gnash::IOChannel.
References bad().
|
virtual |
Seek to the specified position.
Meaningless for a Socket.
Implements gnash::IOChannel.
References _, and gnash::log_error().
|
virtual |
Return current stream position.
Meaningless for a Socket.
Implements gnash::IOChannel.
References _, and gnash::log_error().
|
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 gnash::log_error().
Referenced by gnash::rtmp::RTMP::close(), and gnash::rtmp::RTMP::sendPacket().