Classes | Public Types | Public Member Functions | Protected Attributes

gnash::Network Class Reference

#include <network.h>

Inheritance diagram for gnash::Network:
Inheritance graph
[legend]

List of all members.

Classes

struct  thread_params_t

Public Types

enum  protocols_supported_e {
  NONE, HTTP, HTTPS, RTMP,
  RTMPT, RTMPTS, RTMPE, RTMPS,
  DTN
}
 

This enum contains the list of all supported protocols.

More...
typedef boost::uint8_t byte_t
typedef bool entry_t (thread_params_t *)

Public Member Functions

 Network ()
 ~Network ()
int createServer (void)
 Create a new server. After creating it, then you have to wait for an incoming connection.
int createServer (short port)
int newConnection (void)
 Accept a client connection for the current server.
int newConnection (int fd)
int newConnection (bool block, int fd)
int newConnection (bool block)
bool connectSocket (const std::string &sock)
 Connect to a named pipe.
bool createClient (void)
 Create a client connection to a tcp/ip server.
bool createClient (short port)
bool createClient (const std::string &hostname)
bool createClient (const std::string &hostname, short port)
boost::shared_ptr< cygnal::BufferreadNet ()
 Read from the opened connection.
int readNet (cygnal::Buffer &buffer)
int readNet (int fd, cygnal::Buffer &buffer)
int readNet (int fd, cygnal::Buffer *buffer)
int readNet (cygnal::Buffer &buffer, int timeout)
int readNet (int fd, cygnal::Buffer &buffer, int timeout)
int readNet (byte_t *data, int nbytes)
int readNet (byte_t *data, int nbytes, int timeout)
int readNet (int fd, byte_t *data, int nbytes)
int readNet (int fd, byte_t *data, int nbytes, int timeout)
int writeNet (cygnal::Buffer *buffer)
 Write to the opened connection.
int writeNet (cygnal::Buffer &buffer)
int writeNet (int fd, cygnal::Buffer *buffer)
int writeNet (int fd, cygnal::Buffer &buffer)
int writeNet (const std::string &data)
int writeNet (const byte_t *data, int nbytes)
int writeNet (int fd, const byte_t *buffer, int nbytes)
int writeNet (int fd, const byte_t *buffer, int nbytes, int timeout)
boost::shared_ptr< std::vector
< struct pollfd > > 
waitForNetData (int limit, struct pollfd *fds)
 Wait for sries of file descriptors for data.
fd_set waitForNetData (int limit, fd_set data)
fd_set waitForNetData (std::vector< int > &data)
bool closeNet ()
 Close the connection.
bool closeNet (int fd)
bool closeConnection ()
bool closeConnection (int fd)
void toggleDebug (bool val)
bool netDebug ()
bool send (const char *str)
bool connected () const
void setPort (short x)
short getPort () const
void setFileFd (int x)
int getFileFd () const
int getListenFd () const
void setListenFd (int x)
const std::string & getURL () const
void setURL (const std::string &url)
const std::string & getProtocol () const
void setProtocol (const std::string &proto)
const std::string & getHost () const
void setHost (const std::string &host)
const std::string & getPortStr () const
void setPortStr (const std::string &port)
const std::string & getPath () const
void setPath (const std::string &path)
void setTimeout (int x)
int getTimeout () const
Networkoperator= (Network &net)
void addPollFD (struct pollfd &fd, entry_t *ptr)
void addPollFD (struct pollfd &fd)
void erasePollFD (int fd)
void erasePollFD (std::vector< struct pollfd >::iterator &itt)
struct pollfdgetPollFD (int fd)
struct pollfdgetPollFDPtr ()
void addEntry (int fd, entry_t *func)
entry_tgetEntry (int fd)
size_t sniffBytesReady (int fd)

Protected Attributes

in_addr_t _ipaddr
int _sockfd
int _listenfd
short _port
std::string _portstr
std::string _url
std::string _protocol
std::string _host
std::string _path
bool _connected
bool _debug
int _timeout
size_t _bytes_loaded
std::map< int, entry_t * > _handlers
std::vector< struct pollfd_pollfds
boost::mutex _poll_mutex
boost::mutex _net_mutex

Detailed Description

This is a low level network class for Gnash and Cygnal. This handles the grunt work on both the client side and the server side of a network connection.


Member Typedef Documentation

typedef boost::uint8_t gnash::Network::byte_t

Member Enumeration Documentation

This enum contains the list of all supported protocols.

Enumerator:
NONE 
HTTP 
HTTPS 
RTMP 
RTMPT 
RTMPTS 
RTMPE 
RTMPS 
DTN 

Constructor & Destructor Documentation

gnash::Network::Network (  ) 

References _.

gnash::Network::~Network (  ) 

References closeNet().


Member Function Documentation

void gnash::Network::addEntry ( int  fd,
Network::entry_t func 
)

References _handlers, and _poll_mutex.

void gnash::Network::addPollFD ( struct pollfd fd,
Network::entry_t func 
)
void gnash::Network::addPollFD ( struct pollfd fd  ) 
bool gnash::Network::closeConnection ( int  fd  ) 

References __FUNCTION__, and ogl::close().

bool gnash::Network::closeConnection ( void   ) 

References _connected, and _listenfd.

Referenced by admin_handler().

bool gnash::Network::closeNet (  ) 

Close the connection.

Parameters:
fd The file descritor of the open connection to close.
Returns:
True if the connection was closed, false if it failed.

References _connected.

Referenced by admin_handler(), connection_handler(), event_handler(), main(), gnash::Lirc::~Lirc(), and ~Network().

bool gnash::Network::closeNet ( int  fd  ) 

References _, ogl::close(), and errno.

bool gnash::Network::connected (  )  const [inline]
bool gnash::Network::connectSocket ( const std::string &  sock  ) 

Connect to a named pipe.

Parameters:
sock The name of the named pipe to connect to.
Returns:
True if the connect suceeded, false if it failed.

Referenced by gnash::Lirc::init().

bool gnash::Network::createClient ( void   ) 

Create a client connection to a tcp/ip server.

Parameters:
port The tcp/ip port to use for contacting the server.
hostname The name of the host to connect to. The default is localhost.
Returns:
True if the connect suceeded, false if it failed.

References _port, and gnash::RTMP_PORT.

Referenced by gnash::RTMPClient::connectToServer(), and cygnal::HTTPServer::processPostRequest().

bool gnash::Network::createClient ( short  port  ) 
bool gnash::Network::createClient ( const std::string &  hostname  ) 
bool gnash::Network::createClient ( const std::string &  hostname,
short  port 
)
int gnash::Network::createServer ( short  port  ) 

References _, _debug, _ipaddr, _listenfd, _port, and errno.

int gnash::Network::createServer ( void   ) 

Create a new server. After creating it, then you have to wait for an incoming connection.

Parameters:
port The optional port number to wait on for connections.
Returns:
The file descritor to wait for connections on.

References _port.

Referenced by admin_handler(), connection_handler(), and main().

void gnash::Network::erasePollFD ( int  fd  ) 
void gnash::Network::erasePollFD ( std::vector< struct pollfd >::iterator &  itt  ) 
Network::entry_t * gnash::Network::getEntry ( int  fd  ) 

References _handlers, and _poll_mutex.

int gnash::Network::getFileFd (  )  const [inline]
const std::string& gnash::Network::getHost (  )  const [inline]

Referenced by operator=().

int gnash::Network::getListenFd (  )  const [inline]

Referenced by operator=().

const std::string& gnash::Network::getPath (  )  const [inline]

References _path.

Referenced by operator=().

struct pollfd & gnash::Network::getPollFD ( int  fd  )  [read]

References _poll_mutex, and _pollfds.

struct pollfd * gnash::Network::getPollFDPtr (  )  [read]

References _poll_mutex, and _pollfds.

short gnash::Network::getPort (  )  const [inline]

Referenced by operator=().

const std::string& gnash::Network::getPortStr (  )  const [inline]

Referenced by operator=().

const std::string& gnash::Network::getProtocol (  )  const [inline]

Referenced by operator=().

int gnash::Network::getTimeout (  )  const [inline]

Referenced by operator=().

const std::string& gnash::Network::getURL (  )  const [inline]

Referenced by operator=().

bool gnash::Network::netDebug (  )  [inline]

Referenced by operator=().

int gnash::Network::newConnection ( bool  block,
int  fd 
)

References _, _debug, _listenfd, _port, _sockfd, _timeout, and errno.

int gnash::Network::newConnection ( bool  block  ) 

References _listenfd, and newConnection().

int gnash::Network::newConnection ( void   ) 

Accept a client connection for the current server.

Parameters:
fd The optional file descriptor to wait on for connections.
block True if this should be a blocking wait.
Returns:
The file descriptor of the new connection.

References _listenfd.

Referenced by admin_handler(), connection_handler(), main(), and newConnection().

int gnash::Network::newConnection ( int  fd  ) 

References newConnection().

Network & gnash::Network::operator= ( Network net  ) 
int gnash::Network::readNet ( int  fd,
cygnal::Buffer buffer 
)
int gnash::Network::readNet ( int  fd,
cygnal::Buffer buffer,
int  timeout 
)
int gnash::Network::readNet ( cygnal::Buffer buffer,
int  timeout 
)
int gnash::Network::readNet ( byte_t data,
int  nbytes 
)

References _timeout, and readNet().

int gnash::Network::readNet ( byte_t data,
int  nbytes,
int  timeout 
)

References readNet().

int gnash::Network::readNet ( int  fd,
byte_t data,
int  nbytes 
)

References _timeout, and readNet().

int gnash::Network::readNet ( int  fd,
byte_t data,
int  nbytes,
int  timeout 
)
int gnash::Network::readNet ( int  fd,
cygnal::Buffer buffer 
)
boost::shared_ptr< cygnal::Buffer > gnash::Network::readNet (  ) 

Read from the opened connection.

Parameters:
buffer A Buffer class to hold the data.
timeout An optional timeout for reading data, in seconds.
fd The optional file descriptor to read data from.
nbytes The number of bytes to try to read.
Returns:
The number of bytes read.

Referenced by admin_handler(), gnash::RTMPClient::clientFinish(), gnash::Lirc::getButton(), gnash::Lirc::getKey(), main(), cygnal::Handler::parseFirstRequest(), cygnal::HTTPServer::processPostRequest(), readNet(), gnash::HTTP::recvChunked(), gnash::RTMP::recvMsg(), and gnash::HTTP::recvMsg().

int gnash::Network::readNet ( cygnal::Buffer buffer  ) 

References _timeout, and readNet().

bool gnash::Network::send ( const char *  str  ) 
void gnash::Network::setFileFd ( int  x  )  [inline]
void gnash::Network::setHost ( const std::string &  host  )  [inline]
void gnash::Network::setListenFd ( int  x  )  [inline]
void gnash::Network::setPath ( const std::string &  path  )  [inline]

References _path.

void gnash::Network::setPort ( short  x  )  [inline]

Referenced by connection_handler().

void gnash::Network::setPortStr ( const std::string &  port  )  [inline]
void gnash::Network::setProtocol ( const std::string &  proto  )  [inline]
void gnash::Network::setTimeout ( int  x  )  [inline]
void gnash::Network::setURL ( const std::string &  url  )  [inline]
size_t gnash::Network::sniffBytesReady ( int  fd  ) 

References FIONREAD.

Referenced by cygnal::Handler::parseFirstRequest().

void gnash::Network::toggleDebug ( bool  val  ) 

References _debug.

Referenced by connection_handler(), and main().

fd_set gnash::Network::waitForNetData ( std::vector< int > &  data  ) 
fd_set gnash::Network::waitForNetData ( int  limit,
fd_set  data 
)

References _, _timeout, and errno.

boost::shared_ptr< std::vector< struct pollfd > > gnash::Network::waitForNetData ( int  limit,
struct pollfd fds 
)

Wait for sries of file descriptors for data.

Parameters:
limit The max number of file descriptors to wait for.
Returns:
A vector of the file descriptors that have activity.

References __FUNCTION__, _timeout, gnash::key::i, and POLLRDHUP.

Referenced by event_handler().

int gnash::Network::writeNet ( int  fd,
cygnal::Buffer buffer 
)
int gnash::Network::writeNet ( const byte_t data,
int  nbytes 
)

References _timeout, and writeNet().

int gnash::Network::writeNet ( cygnal::Buffer buffer  ) 

Write to the opened connection.

Parameters:
buffer A Buffer class holding the data.
timeout An optional timeout for writing data, in seconds.
fd The optional file descriptor to write data to from.
nbytes The number of bytes to try to write..
Returns:
The number of bytes read.

References cygnal::Buffer::allocated(), and cygnal::Buffer::reference().

Referenced by admin_handler(), gnash::RTMPClient::clientFinish(), gnash::RTMPClient::handShakeRequest(), main(), gnash::DiskStream::play(), cygnal::HTTPServer::processClientRequest(), cygnal::HTTPServer::processGetRequest(), cygnal::HTTPServer::processPostRequest(), gnash::RTMP::sendMsg(), gnash::HTTP::sendMsg(), cygnal::RTMPServer::sendToClient(), and writeNet().

int gnash::Network::writeNet ( int  fd,
const byte_t buffer,
int  nbytes,
int  timeout 
)
int gnash::Network::writeNet ( int  fd,
const byte_t buffer,
int  nbytes 
)

References _timeout, and writeNet().

int gnash::Network::writeNet ( const std::string &  data  ) 

References writeNet().

int gnash::Network::writeNet ( int  fd,
cygnal::Buffer buffer 
)
int gnash::Network::writeNet ( cygnal::Buffer buffer  ) 

Member Data Documentation

size_t gnash::Network::_bytes_loaded [protected]
bool gnash::Network::_connected [protected]
bool gnash::Network::_debug [protected]
std::map<int, entry_t *> gnash::Network::_handlers [protected]

Referenced by addEntry(), addPollFD(), and getEntry().

std::string gnash::Network::_host [protected]

Referenced by operator=().

in_addr_t gnash::Network::_ipaddr [protected]

Referenced by createServer().

int gnash::Network::_listenfd [protected]
boost::mutex gnash::Network::_net_mutex [protected]

Referenced by writeNet().

std::string gnash::Network::_path [protected]

Referenced by operator=().

boost::mutex gnash::Network::_poll_mutex [protected]
std::vector<struct pollfd> gnash::Network::_pollfds [protected]
short gnash::Network::_port [protected]
std::string gnash::Network::_portstr [protected]

Referenced by operator=().

std::string gnash::Network::_protocol [protected]

Reimplemented in cygnal::Handler.

Referenced by operator=().

int gnash::Network::_sockfd [protected]

Referenced by newConnection().

int gnash::Network::_timeout [protected]

Reimplemented in gnash::RTMP.

Referenced by newConnection(), operator=(), readNet(), waitForNetData(), and writeNet().

std::string gnash::Network::_url [protected]

Referenced by operator=().


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