nidas
v1.2-1520
|
#include <MultipleUDPSockets.h>
Public Member Functions | |
MultipleUDPSockets () | |
MultipleUDPSockets (const MultipleUDPSockets &x) | |
MultipleUDPSockets * | clone () const |
Derived classes must provide clone. More... | |
IOChannel * | connect () throw (nidas::util::IOException) |
Establish a connection. More... | |
void | connected (nidas::util::DatagramSocket *sock, const nidas::util::Inet4PacketInfoX &pktinfo) throw () |
size_t | getBufferSize () const throw () |
Return suggested buffer length. More... | |
size_t | read (void *, size_t) throw (nidas::util::IOException) |
A McSocketUDP shouldn't be used to do any actual reads or writes, it just sets up the connection. More... | |
size_t | write (const void *buf, size_t len) throw (nidas::util::IOException) |
A McSocketUDP shouldn't be used to do any actual reads or writes, it just sets up the connection. More... | |
size_t | write (const struct iovec *iov, int iovcnt) throw (nidas::util::IOException) |
A McSocketUDP shouldn't be used to do any actual reads or writes, it just sets up the connection. More... | |
void | close () throw (nidas::util::IOException) |
int | getFd () const |
void | fromDOMElement (const xercesc::DOMElement *) throw (nidas::util::InvalidParameterException) |
Initialize myself from a xercesc::DOMElement. More... | |
void | addClient (const ConnectionInfo &info) |
From the Inet4PacketInfoX associated with the received request, determine if we need to create a new socket to send data to the requester. More... | |
void | removeClient (const nidas::util::Inet4SocketAddress &remoteSAddr) |
void | removeClient (nidas::util::DatagramSocket *) |
void | setDataPort (unsigned short val) |
unsigned short | getDataPort () const |
void | setRequestType (enum McSocketRequest val) |
enum McSocketRequest | getRequestType () const |
bool | isRequester () const |
Does this McSocket request connections, or does it listen for incoming connections. More... | |
void | setRequester (bool val) |
void | setName (const std::string &val) |
const std::string & | getName () const |
void | requestConnection (IOChannelRequester *service) throw (nidas::util::IOException) |
After the IOChannel is configured, a user of IOChannel calls requestConnection to get things started. More... | |
virtual 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... | |
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... | |
void | setInet4McastSocketAddress (const nidas::util::Inet4SocketAddress &val) |
const nidas::util::Inet4SocketAddress & | getInet4McastSocketAddress () 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 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... | |
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 () |
Protected Attributes | |
IOChannelRequester * | _iochanRequester |
MyMcSocket | _mcsocket |
Private Member Functions | |
void | handleChangedSockets () |
Private Attributes | |
nidas::util::Mutex | _socketMutex |
std::list< std::pair < nidas::util::DatagramSocket *, nidas::util::Inet4SocketAddress > > | _sockets |
std::list< std::pair < nidas::util::DatagramSocket *, nidas::util::Inet4SocketAddress > > | _pendingSockets |
std::list < nidas::util::DatagramSocket * > | _pendingRemoveSockets |
std::map < nidas::util::Inet4SocketAddress, nidas::util::Inet4Address > | _multicastInterfaces |
The local multicast interface of each remote client. More... | |
std::map < nidas::util::Inet4Address, std::set < nidas::util::Inet4SocketAddress > > | _multicastClients |
Remote clients of each multicast interface. More... | |
std::map < nidas::util::Inet4Address, nidas::util::DatagramSocket * > | _multicastSockets |
Socket of each multicast interface. More... | |
std::map < nidas::util::Inet4SocketAddress, nidas::util::DatagramSocket * > | _unicastSockets |
Unicast Sockets for each destination. More... | |
bool | _socketsChanged |
unsigned short | _dataPortNumber |
MultipleUDPSockets::MultipleUDPSockets | ( | ) |
References nidas::core::McSocketUDP::setName().
Referenced by clone().
MultipleUDPSockets::MultipleUDPSockets | ( | const MultipleUDPSockets & | x | ) |
References nidas::core::McSocketUDP::setName().
void MultipleUDPSockets::addClient | ( | const ConnectionInfo & | info | ) |
From the Inet4PacketInfoX associated with the received request, determine if we need to create a new socket to send data to the requester.
If this is a new destination address for unicast packets add a new nidas::util::DatagramSocket. Or, if the requester sent a multicast request, and it was received on an interface which has not received requests before, then add a new nidas::util::MulticastSocket on that interface.
References _multicastClients, _multicastInterfaces, _multicastSockets, _pendingSockets, _socketMutex, _socketsChanged, _unicastSockets, nidas::util::Inet4NetworkInterface::getAddress(), getDataPort(), nidas::core::ConnectionInfo::getDestinationAddress(), nidas::util::Inet4Address::getHostAddress(), nidas::util::Inet4SocketAddress::getInet4Address(), nidas::core::McSocketUDP::getInet4McastSocketAddress(), nidas::core::ConnectionInfo::getInterface(), nidas::core::ConnectionInfo::getRemoteSocketAddress(), ILOG, nidas::util::Inet4Address::isMultiCastAddress(), nidas::util::Mutex::lock(), nidas::util::MulticastSocket::setInterface(), nidas::util::MulticastSocket::setMulticastLoop(), nidas::util::Inet4SocketAddress::setPort(), nidas::util::Inet4SocketAddress::toAddressString(), and nidas::util::Mutex::unlock().
Referenced by connect().
|
virtual |
Derived classes must provide clone.
Reimplemented from nidas::core::McSocketUDP.
References MultipleUDPSockets().
|
virtual |
Reimplemented from nidas::core::McSocketUDP.
References _pendingSockets, _socketMutex, _sockets, _socketsChanged, nidas::util::DatagramSocket::close(), nidas::util::Mutex::lock(), and nidas::util::Mutex::unlock().
|
virtual |
Establish a connection.
On return, the connection has been established. It may return a new instance of an IOChannel.
Reimplemented from nidas::core::McSocketUDP.
References nidas::core::McSocketUDP::_mcsocket, nidas::util::McSocket< SocketT >::accept(), addClient(), nidas::util::Inet4PacketInfo::getDestinationAddress(), nidas::util::Inet4PacketInfo::getInterface(), nidas::util::Inet4PacketInfoX::getRemoteSocketAddress(), nidas::core::McSocketUDP::isNonBlocking(), nidas::core::IOChannel::setConnectionInfo(), and nidas::core::DatagramSocket::setNonBlocking().
|
virtual |
Reimplemented from nidas::core::McSocketUDP.
References ILOG.
|
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.
Reimplemented from nidas::core::McSocketUDP.
References nidas::util::Process::expandEnvVars(), nidas::util::Inet4Address::getByName(), nidas::util::Logger::getInstance(), nidas::core::XDOMAttr::getName(), nidas::util::Logger::log(), LOG_WARNING, NIDAS_MULTICAST_ADDR, NIDAS_SVC_REQUEST_PORT_UDP, port, and nidas::core::UDP_PROCESSED_SAMPLE_FEED.
|
virtual |
Return suggested buffer length.
Reimplemented from nidas::core::IOChannel.
References _socketMutex, _sockets, 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().
|
inline |
References _dataPortNumber.
Referenced by addClient().
|
inlinevirtualinherited |
What DSM is this IOChannel connected to? May be NULL.
Referenced by nidas::core::FileSet::setDir(), and nidas::core::FileSet::setFileName().
|
virtual |
Reimplemented from nidas::core::McSocketUDP.
References _socketMutex, _sockets, and nidas::util::DatagramSocket::getFd().
|
inlineinherited |
References nidas::core::McSocketUDP::_mcsocket, and nidas::util::McSocket< SocketT >::getInet4McastSocketAddress().
Referenced by addClient().
|
inlinevirtualinherited |
Implements nidas::core::IOChannel.
References nidas::core::McSocketUDP::_name.
|
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().
|
inlinevirtualinherited |
Reimplemented in nidas::core::FileSet.
Referenced by nidas::core::SampleOutputBase::getReconnectDelaySecs().
|
inlinevirtualinherited |
Reimplemented from nidas::core::IOChannel.
References nidas::core::McSocketUDP::_mcsocket, and nidas::util::McSocket< SocketT >::getRequestType().
|
private |
|
inlinevirtualinherited |
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.
References nidas::core::McSocketUDP::_newInput.
|
inlinevirtualinherited |
Return isNonBlocking() of underlying socket.
Implements nidas::core::IOChannel.
References nidas::core::McSocketUDP::_nonBlocking.
Referenced by connect(), nidas::core::McSocketUDP::connect(), and nidas::core::McSocketUDP::connected().
|
inlineinherited |
Does this McSocket request connections, or does it listen for incoming connections.
References nidas::core::McSocketUDP::_amRequester.
Referenced by nidas::core::McSocketUDP::connect().
|
inlinevirtual |
A McSocketUDP shouldn't be used to do any actual reads or writes, it just sets up the connection.
The returned IOChannel should be used to read/write. Calling this method will fail with an assert.
Reimplemented from nidas::core::McSocketUDP.
void MultipleUDPSockets::removeClient | ( | const nidas::util::Inet4SocketAddress & | remoteSAddr | ) |
void MultipleUDPSockets::removeClient | ( | nidas::util::DatagramSocket * | dsock | ) |
|
virtualinherited |
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 |
|
inline |
References _dataPortNumber.
|
inlinevirtualinherited |
What DSM is this IOChannel connected to?
Referenced by nidas::core::SampleOutputBase::fromDOMElement(), nidas::core::SampleOutputBase::SampleOutputBase(), and nidas::core::SampleOutputBase::setIOChannel().
|
inlineinherited |
|
inlinevirtualinherited |
Implements nidas::core::IOChannel.
References nidas::core::McSocketUDP::_name.
Referenced by nidas::core::McSocketUDP::McSocketUDP(), and MultipleUDPSockets().
|
inlinevirtualinherited |
Do setNonBlocking(val) on underlying socket.
Implements nidas::core::IOChannel.
References nidas::core::McSocketUDP::_nonBlocking.
|
inlineinherited |
References nidas::core::McSocketUDP::_amRequester.
|
inlinevirtualinherited |
Reimplemented from nidas::core::IOChannel.
References nidas::core::McSocketUDP::_mcsocket, and nidas::util::McSocket< SocketT >::setRequestType().
|
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.
|
virtual |
A McSocketUDP shouldn't be used to do any actual reads or writes, it just sets up the connection.
The returned IOChannel should be used to read/write. Calling this method will fail with an assert.
Reimplemented from nidas::core::McSocketUDP.
References ILOG, len, nidas::util::DatagramSocket::sendto(), and nidas::util::Exception::what().
|
virtual |
A McSocketUDP shouldn't be used to do any actual reads or writes, it just sets up the connection.
The returned IOChannel should be used to read/write. Calling this method will fail with an assert.
Reimplemented from nidas::core::McSocketUDP.
References ILOG, nidas::util::DatagramSocket::sendto(), and nidas::util::Exception::what().
|
inlinevirtualinherited |
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 in nidas::core::DatagramSocket.
Referenced by nidas::dynld::SampleInputStream::setIOChannel().
|
private |
Referenced by getDataPort(), and setDataPort().
|
protectedinherited |
Referenced by nidas::core::McSocketUDP::connected().
|
protectedinherited |
Referenced by nidas::core::McSocketUDP::close(), connect(), nidas::core::McSocketUDP::connect(), nidas::core::McSocketUDP::getInet4McastSocketAddress(), nidas::core::McSocketUDP::getRequestType(), nidas::core::McSocketUDP::setInet4McastSocketAddress(), and nidas::core::McSocketUDP::setRequestType().
|
private |
Remote clients of each multicast interface.
Referenced by addClient(), and removeClient().
|
private |
The local multicast interface of each remote client.
Referenced by addClient(), and removeClient().
|
private |
Socket of each multicast interface.
Referenced by addClient(), and removeClient().
|
private |
Referenced by handleChangedSockets(), and removeClient().
|
private |
Referenced by addClient(), close(), and handleChangedSockets().
|
mutableprivate |
Referenced by addClient(), close(), getBufferSize(), getFd(), handleChangedSockets(), and removeClient().
|
private |
Referenced by close(), getBufferSize(), getFd(), and handleChangedSockets().
|
private |
Referenced by addClient(), close(), handleChangedSockets(), and removeClient().
|
private |
Unicast Sockets for each destination.
Referenced by addClient(), and removeClient().