nidas  v1.2-1520
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
nidas::core::DatagramSocket Class Reference

Implementation of an IOChannel, over a DatagramSocket. More...

#include <DatagramSocket.h>

Inheritance diagram for nidas::core::DatagramSocket:
Inheritance graph
[legend]

Public Member Functions

 DatagramSocket ()
 Constructor. More...
 
 DatagramSocket (const DatagramSocket &x)
 Copy constructor. More...
 
DatagramSocketoperator= (const DatagramSocket &rhs)
 
 DatagramSocket (nidas::util::DatagramSocket *sock)
 
 ~DatagramSocket ()
 
DatagramSocketclone () const
 Derived classes must provide clone. More...
 
void requestConnection (IOChannelRequester *service) throw (nidas::util::IOException)
 After the IOChannel is configured, a user of IOChannel calls requestConnection to get things started. More...
 
IOChannelconnect () throw (nidas::util::IOException)
 Establish a connection. More...
 
bool isNewInput () const
 Some IOChannels, namely FileSet, which opens successive files, need to indicate when a read is from the start of a new file. More...
 
bool writeNidasHeader () const
 Should the NIDAS header be written to this IOChannel? NIDAS headers are not written to DatagramSockets, because there is no guarantee they will get there. More...
 
std::list
< nidas::util::Inet4NetworkInterface
getInterfaces () const throw (nidas::util::IOException)
 
void setNonBlocking (bool val) throw (nidas::util::IOException)
 Do setNonBlocking(val) on underlying socket. More...
 
bool isNonBlocking () const throw (nidas::util::IOException)
 Return isNonBlocking() of underlying socket. More...
 
size_t getBufferSize () const throw ()
 Return suggested buffer length. More...
 
size_t read (void *buf, size_t len) throw (nidas::util::IOException)
 Do the actual hardware read. More...
 
size_t write (const void *buf, size_t len) throw (nidas::util::IOException)
 Do the actual hardware write. More...
 
size_t write (const struct iovec *iov, int iovcnt) throw (nidas::util::IOException)
 Do the actual hardware write. More...
 
void close () throw (nidas::util::IOException)
 
int getFd () const
 
const std::string & getName () const
 
void setName (const std::string &val)
 
const std::string & getUnixPath () const
 Get the unix path name. More...
 
void setUnixPath (const std::string &unixPath)
 Set the pathname for the unix socket connection. More...
 
void setSocketAddress (const nidas::util::SocketAddress &val)
 Set address for this socket. More...
 
const nidas::util::SocketAddressgetSocketAddress () throw (nidas::util::UnknownHostException)
 
void setHostPort (const std::string &host, unsigned short port)
 Set the hostname and port of the remote connection. More...
 
void setPort (unsigned short port)
 Set the the local port number. More...
 
const std::string & getHost () const
 Get the name of the remote host. More...
 
unsigned short getPort () const
 
void fromDOMElement (const xercesc::DOMElement *) throw (nidas::util::InvalidParameterException)
 Initialize myself from a xercesc::DOMElement. More...
 
virtual void setRequestType (enum McSocketRequest)
 
virtual enum McSocketRequest getRequestType () const
 
virtual int getReconnectDelaySecs () const
 
virtual const ConnectionInfogetConnectionInfo () const
 What is the IP address of the host at the other end of the connection. More...
 
virtual void setConnectionInfo (const ConnectionInfo &val)
 
virtual void flush () throw (nidas::util::IOException)
 Default flush implementation does nothing. More...
 
virtual dsm_time_t createFile (dsm_time_t t, bool exact)
 Request that an IOChannel open a new file, with a name based on a time. More...
 
virtual void setDSMConfig (const DSMConfig *val)
 What DSM is this IOChannel connected to? More...
 
virtual const DSMConfiggetDSMConfig () const
 What DSM is this IOChannel connected to? May be NULL. More...
 
virtual xercesc::DOMElement * toDOMParent (xercesc::DOMElement *parent, bool complete) const throw (xercesc::DOMException)
 Create a DOMElement and append it to the parent. More...
 
virtual xercesc::DOMElement * toDOMElement (xercesc::DOMElement *node, bool complete) const throw (xercesc::DOMException)
 Add my content into a DOMElement. More...
 

Static Public Member Functions

static IOChannelcreateIOChannel (const xercesc::DOMElement *node) throw (nidas::util::InvalidParameterException)
 
static const XMLCh * getNamespaceURI ()
 

Private Attributes

nidas::util::auto_ptr
< nidas::util::SocketAddress
_sockAddr
 
std::string _host
 
unsigned short _port
 
std::string _unixPath
 
nidas::util::DatagramSocket_nusocket
 
std::string _name
 
IOChannelRequester_iochanRequester
 
bool _nonBlocking
 

Detailed Description

Implementation of an IOChannel, over a DatagramSocket.

Constructor & Destructor Documentation

DatagramSocket::DatagramSocket ( )

Constructor.

References setName().

Referenced by clone().

DatagramSocket::DatagramSocket ( const DatagramSocket x)

Copy constructor.

References _sockAddr, and setName().

DatagramSocket::DatagramSocket ( nidas::util::DatagramSocket sock)
DatagramSocket::~DatagramSocket ( )

Member Function Documentation

DatagramSocket * DatagramSocket::clone ( ) const
virtual

Derived classes must provide clone.

Implements nidas::core::IOChannel.

References DatagramSocket().

void nidas::core::DatagramSocket::close ( )
throw (nidas::util::IOException
)
inlinevirtual
IOChannel * DatagramSocket::connect ( )
throw (nidas::util::IOException
)
virtual
virtual dsm_time_t nidas::core::IOChannel::createFile ( dsm_time_t  t,
bool  exact 
)
inlinevirtualinherited

Request that an IOChannel open a new file, with a name based on a time.

This should be implemented by derived classes which write to disk files. Other derived classes (e.g. sockets) can just use this default implementation - basically ignoring the request.

Parameters
tTime to use when creating file name.
exactUse exact time when creating file name, else the time is adjusted to an even time interval.

Reimplemented in nidas::core::FileSet.

Referenced by nidas::core::IOStream::createFile().

IOChannel * IOChannel::createIOChannel ( const xercesc::DOMElement *  node)
throw (nidas::util::InvalidParameterException
)
staticinherited
virtual void nidas::core::IOChannel::flush ( )
throw (nidas::util::IOException
)
inlinevirtualinherited
void DatagramSocket::fromDOMElement ( const xercesc::DOMElement *  )
throw (nidas::util::InvalidParameterException
)
virtual
size_t DatagramSocket::getBufferSize ( ) const
throw (
)
virtual

Return suggested buffer length.

Reimplemented from nidas::core::IOChannel.

References _nusocket, and nidas::util::DatagramSocket::getReceiveBufferSize().

virtual const ConnectionInfo& nidas::core::IOChannel::getConnectionInfo ( ) const
inlinevirtualinherited

What is the IP address of the host at the other end of the connection.

If this IOChannel is not a socket then return INADDR_ANY, using the default constructor of an Inet4Address. Socket subclasses should override this.

Referenced by nidas::dynld::SampleInputStream::setIOChannel().

virtual const DSMConfig* nidas::core::IOChannel::getDSMConfig ( ) const
inlinevirtualinherited

What DSM is this IOChannel connected to? May be NULL.

Referenced by nidas::core::FileSet::setDir(), and nidas::core::FileSet::setFileName().

int nidas::core::DatagramSocket::getFd ( ) const
inlinevirtual
const std::string& nidas::core::DatagramSocket::getHost ( ) const
inline

Get the name of the remote host.

References _host.

std::list<nidas::util::Inet4NetworkInterface> nidas::core::DatagramSocket::getInterfaces ( ) const
throw (nidas::util::IOException
)
inline
const std::string& nidas::core::DatagramSocket::getName ( ) const
inlinevirtual

Implements nidas::core::IOChannel.

References _name.

Referenced by connect(), and ~DatagramSocket().

static const XMLCh* nidas::core::DOMable::getNamespaceURI ( )
inlinestaticinherited
unsigned short nidas::core::DatagramSocket::getPort ( ) const
inline

References _port.

virtual int nidas::core::IOChannel::getReconnectDelaySecs ( ) const
inlinevirtualinherited
virtual enum McSocketRequest nidas::core::IOChannel::getRequestType ( ) const
inlinevirtualinherited
const n_u::SocketAddress & DatagramSocket::getSocketAddress ( )
throw (nidas::util::UnknownHostException
)
const std::string& nidas::core::DatagramSocket::getUnixPath ( ) const
inline

Get the unix path name.

References _unixPath.

Referenced by getSocketAddress().

bool nidas::core::DatagramSocket::isNewInput ( ) const
inlinevirtual

Some IOChannels, namely FileSet, which opens successive files, need to indicate when a read is from the start of a new file.

This method is used by code which may need to do special things at the beginning of a file, like read a SampleInputHeader.

Reimplemented from nidas::core::IOChannel.

bool nidas::core::DatagramSocket::isNonBlocking ( ) const
throw (nidas::util::IOException
)
inlinevirtual

Return isNonBlocking() of underlying socket.

Implements nidas::core::IOChannel.

References _nonBlocking, _nusocket, and nidas::util::DatagramSocket::isNonBlocking().

Referenced by connect().

DatagramSocket & DatagramSocket::operator= ( const DatagramSocket rhs)
size_t nidas::core::DatagramSocket::read ( void *  buf,
size_t  len 
)
throw (nidas::util::IOException
)
inlinevirtual

Do the actual hardware read.

Implements nidas::core::IOChannel.

References _nusocket, len, and nidas::util::DatagramSocket::recv().

void DatagramSocket::requestConnection ( IOChannelRequester )
throw (nidas::util::IOException
)
virtual

After the IOChannel is configured, a user of IOChannel calls requestConnection to get things started.

It is like opening a device, but in the case of server sockets, it just starts a thread to wait on connections. Only when the IOChannelRequester::connected() method is called back is the channel actually open and ready for IO. The IOChannel* returned by IOChannelRequester::connected may be another instance of an IOChannel.

Implements nidas::core::IOChannel.

virtual void nidas::core::IOChannel::setConnectionInfo ( const ConnectionInfo val)
inlinevirtualinherited
virtual void nidas::core::IOChannel::setDSMConfig ( const DSMConfig val)
inlinevirtualinherited
void DatagramSocket::setHostPort ( const std::string &  host,
unsigned short  port 
)

Set the hostname and port of the remote connection.

This method does not try to do a DNS host lookup. The DNS lookup will be done at connect time.

References _host, _port, and port.

void nidas::core::DatagramSocket::setName ( const std::string &  val)
inlinevirtual

Implements nidas::core::IOChannel.

References _name.

Referenced by DatagramSocket(), getSocketAddress(), and operator=().

void nidas::core::DatagramSocket::setNonBlocking ( bool  val)
throw (nidas::util::IOException
)
inlinevirtual

Do setNonBlocking(val) on underlying socket.

Implements nidas::core::IOChannel.

References _nonBlocking, _nusocket, and nidas::util::DatagramSocket::setNonBlocking().

Referenced by nidas::core::MultipleUDPSockets::connect().

void nidas::core::DatagramSocket::setPort ( unsigned short  port)

Set the the local port number.

virtual void nidas::core::IOChannel::setRequestType ( enum McSocketRequest  )
inlinevirtualinherited
void DatagramSocket::setSocketAddress ( const nidas::util::SocketAddress val)

Set address for this socket.

If address is INADDR_ANY or an address of a local interface, then a bind will be done to that address. If the address is a remote host, then a connect will be done, which sets the default sendto address.

References _sockAddr, and nidas::util::SocketAddress::clone().

Referenced by getSocketAddress().

void DatagramSocket::setUnixPath ( const std::string &  unixPath)

Set the pathname for the unix socket connection.

References _unixPath.

xercesc::DOMElement * DOMable::toDOMElement ( xercesc::DOMElement *  node,
bool  complete 
) const
throw (xercesc::DOMException
)
virtualinherited
xercesc::DOMElement * DOMable::toDOMParent ( xercesc::DOMElement *  parent,
bool  complete 
) const
throw (xercesc::DOMException
)
virtualinherited
size_t nidas::core::DatagramSocket::write ( const void *  buf,
size_t  len 
)
throw (nidas::util::IOException
)
inlinevirtual

Do the actual hardware write.

Implements nidas::core::IOChannel.

References _nusocket, len, and nidas::util::DatagramSocket::send().

size_t nidas::core::DatagramSocket::write ( const struct iovec *  iov,
int  iovcnt 
)
throw (nidas::util::IOException
)
inlinevirtual

Do the actual hardware write.

Implements nidas::core::IOChannel.

References _nusocket, and nidas::util::DatagramSocket::send().

bool nidas::core::DatagramSocket::writeNidasHeader ( ) const
inlinevirtual

Should the NIDAS header be written to this IOChannel? NIDAS headers are not written to DatagramSockets, because there is no guarantee they will get there.

Reimplemented from nidas::core::IOChannel.

Member Data Documentation

std::string nidas::core::DatagramSocket::_host
private
IOChannelRequester* nidas::core::DatagramSocket::_iochanRequester
private

Referenced by operator=().

std::string nidas::core::DatagramSocket::_name
private

Referenced by getName(), operator=(), and setName().

bool nidas::core::DatagramSocket::_nonBlocking
private
nidas::util::DatagramSocket* nidas::core::DatagramSocket::_nusocket
private
unsigned short nidas::core::DatagramSocket::_port
private
nidas::util::auto_ptr<nidas::util::SocketAddress> nidas::core::DatagramSocket::_sockAddr
private
std::string nidas::core::DatagramSocket::_unixPath
private

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