nidas
v1.2-1520
|
Implementation of an IOChannel, over a DatagramSocket. More...
#include <DatagramSocket.h>
Public Member Functions | |
DatagramSocket () | |
Constructor. More... | |
DatagramSocket (const DatagramSocket &x) | |
Copy constructor. More... | |
DatagramSocket & | operator= (const DatagramSocket &rhs) |
DatagramSocket (nidas::util::DatagramSocket *sock) | |
~DatagramSocket () | |
DatagramSocket * | clone () 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... | |
IOChannel * | connect () 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::SocketAddress & | getSocketAddress () 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 ConnectionInfo & | getConnectionInfo () 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 DSMConfig * | getDSMConfig () 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 IOChannel * | createIOChannel (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 |
Implementation of an IOChannel, over a DatagramSocket.
DatagramSocket::DatagramSocket | ( | const DatagramSocket & | x | ) |
DatagramSocket::DatagramSocket | ( | nidas::util::DatagramSocket * | sock | ) |
DatagramSocket::~DatagramSocket | ( | ) |
References _nusocket, close(), getName(), nidas::util::Exception::what(), and WLOG.
|
virtual |
|
inlinevirtual |
Implements nidas::core::IOChannel.
References _nusocket, and nidas::util::DatagramSocket::close().
Referenced by ~DatagramSocket().
|
virtual |
Establish a connection.
On return, the connection has been established. It may return a new instance of an IOChannel.
Implements nidas::core::IOChannel.
References _nusocket, nidas::util::DatagramSocket::bind(), nidas::util::DatagramSocket::connect(), nidas::util::SocketAddress::getConstSockAddrPtr(), nidas::util::SocketAddress::getFamily(), nidas::util::Inet4SocketAddress::getInet4Address(), getName(), getSocketAddress(), isNonBlocking(), nidas::util::DatagramSocket::setNonBlocking(), and nidas::util::Exception::what().
|
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.
t | Time to use when creating file name. |
exact | Use 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().
|
staticinherited |
References nidas::core::DOMObjectFactory::createObject(), nidas::core::Socket::createSocket(), nidas::util::Process::expandEnvVars(), nidas::core::XDOMElement::getAttributeValue(), and nidas::core::XDOMElement::getNodeName().
Referenced by nidas::dynld::psql::PSQLSampleOutput::fromDOMElement(), nidas::core::DSMService::fromDOMElement(), nidas::dynld::isff::GOESOutput::fromDOMElement(), nidas::core::SampleOutputBase::fromDOMElement(), and nidas::dynld::SampleInputStream::fromDOMElement().
|
inlinevirtualinherited |
Default flush implementation does nothing.
Reimplemented in nidas::dynld::isff::GOESXmtr, nidas::dynld::isff::SE_GOESXmtr, and nidas::dynld::psql::PSQLChannel.
Referenced by nidas::core::SampleArchiver::disconnect(), and nidas::core::IOStream::flush().
|
virtual |
Initialize myself from a xercesc::DOMElement.
Implements nidas::core::DOMable.
References nidas::util::Process::expandEnvVars(), nidas::util::Inet4Address::getByName(), nidas::core::XDOMAttr::getName(), port, nidas::util::Exception::what(), and WLOG.
|
virtual |
Return suggested buffer length.
Reimplemented from nidas::core::IOChannel.
References _nusocket, and nidas::util::DatagramSocket::getReceiveBufferSize().
|
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().
|
inlinevirtualinherited |
What DSM is this IOChannel connected to? May be NULL.
Referenced by nidas::core::FileSet::setDir(), and nidas::core::FileSet::setFileName().
|
inlinevirtual |
Implements nidas::core::IOChannel.
References _nusocket, and nidas::util::DatagramSocket::getFd().
|
inline |
Get the name of the remote host.
References _host.
|
inline |
References _nusocket, and nidas::util::DatagramSocket::getInterfaces().
|
inlinevirtual |
Implements nidas::core::IOChannel.
References _name.
Referenced by connect(), and ~DatagramSocket().
|
inlinestaticinherited |
References nidas::core::DOMable::namespaceURI.
Referenced by nidas::dynld::UDPSampleOutput::getProjectDOM(), nidas::core::Dataset::toDOMElement(), nidas::core::ProjectConfig::toDOMElement(), nidas::core::Dataset::toDOMParent(), nidas::core::ProjectConfig::toDOMParent(), nidas::core::Datasets::toDOMParent(), nidas::core::ProjectConfigs::toDOMParent(), nidas::core::DSMConfig::toDOMParent(), nidas::core::Project::toDOMParent(), nidas::core::Site::toDOMParent(), nidas::core::SampleTag::toDOMParent(), nidas::core::ServerSocket::toDOMParent(), nidas::core::Variable::toDOMParent(), nidas::core::DSMSensor::toDOMParent(), nidas::core::Datasets::writeXML(), and nidas::core::ProjectConfigs::writeXML().
|
inline |
References _port.
|
inlinevirtualinherited |
Reimplemented in nidas::core::FileSet.
Referenced by nidas::core::SampleOutputBase::getReconnectDelaySecs().
|
inlinevirtualinherited |
Reimplemented in nidas::core::Socket, nidas::core::McSocketUDP, and nidas::core::McSocket.
const n_u::SocketAddress & DatagramSocket::getSocketAddress | ( | ) | ||
throw | ( | nidas::util::UnknownHostException | ||
) |
References _host, _port, _sockAddr, _unixPath, nidas::util::Inet4Address::getByName(), getUnixPath(), setName(), and setSocketAddress().
Referenced by connect().
|
inline |
|
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.
|
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 | ) |
References _host, _iochanRequester, _name, _nonBlocking, _nusocket, _port, _sockAddr, _unixPath, and setName().
|
inlinevirtual |
Do the actual hardware read.
Implements nidas::core::IOChannel.
References _nusocket, len, and nidas::util::DatagramSocket::recv().
|
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.
|
inlinevirtualinherited |
|
inlinevirtualinherited |
What DSM is this IOChannel connected to?
Referenced by nidas::core::SampleOutputBase::fromDOMElement(), nidas::core::SampleOutputBase::SampleOutputBase(), and nidas::core::SampleOutputBase::setIOChannel().
void DatagramSocket::setHostPort | ( | const std::string & | host, |
unsigned short | port | ||
) |
|
inlinevirtual |
Implements nidas::core::IOChannel.
References _name.
Referenced by DatagramSocket(), getSocketAddress(), and operator=().
|
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.
|
inlinevirtualinherited |
Reimplemented in nidas::core::Socket, nidas::core::McSocketUDP, and nidas::core::McSocket.
Referenced by nidas::dynld::XMLConfigService::schedule().
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.
|
virtualinherited |
Add my content into a DOMElement.
Reimplemented in nidas::core::DSMSensor, nidas::core::Variable, nidas::core::ServerSocket, nidas::core::SampleTag, nidas::core::Site, nidas::core::Project, and nidas::core::DSMConfig.
Referenced by nidas::core::ServerSocket::toDOMParent().
|
virtualinherited |
Create a DOMElement and append it to the parent.
Reimplemented in nidas::core::DSMSensor, nidas::core::Variable, nidas::core::ServerSocket, nidas::core::SampleTag, nidas::core::Site, nidas::core::Project, and nidas::core::DSMConfig.
|
inlinevirtual |
Do the actual hardware write.
Implements nidas::core::IOChannel.
References _nusocket, len, and nidas::util::DatagramSocket::send().
|
inlinevirtual |
Do the actual hardware write.
Implements nidas::core::IOChannel.
References _nusocket, and nidas::util::DatagramSocket::send().
|
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.
|
private |
Referenced by getHost(), getSocketAddress(), operator=(), and setHostPort().
|
private |
Referenced by operator=().
|
private |
Referenced by getName(), operator=(), and setName().
|
private |
Referenced by isNonBlocking(), operator=(), and setNonBlocking().
|
private |
Referenced by close(), connect(), getBufferSize(), getFd(), getInterfaces(), isNonBlocking(), operator=(), read(), setNonBlocking(), write(), and ~DatagramSocket().
|
private |
Referenced by getPort(), getSocketAddress(), operator=(), and setHostPort().
|
private |
Referenced by DatagramSocket(), getSocketAddress(), operator=(), and setSocketAddress().
|
private |
Referenced by getSocketAddress(), getUnixPath(), operator=(), and setUnixPath().