nidas
v1.2-1520
|
Implementation of an IOChannel, over a Socket. More...
#include <Socket.h>
Classes | |
class | ConnectionThread |
Public Member Functions | |
Socket () | |
Constructor. More... | |
Socket (nidas::util::Socket *sock) | |
Constructor from a connected nidas::util::Socket. More... | |
~Socket () | |
Socket * | 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,nidas::util::UnknownHostException) |
Establish a connection. 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 | setRequestType (enum McSocketRequest val) |
enum McSocketRequest | getRequestType () const |
void | setKeepAliveIdleSecs (int val) throw (nidas::util::IOException) |
Do setKeepAliveIdleSecs(int secs) on underlying socket. More... | |
int | getKeepAliveIdleSecs () const throw (nidas::util::IOException) |
Return getKeepAliveIdleSecs() on underlying socket. 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) |
nidas::util::Inet4Address | getRemoteInet4Address () |
void | setRemoteHostPort (const std::string &host, unsigned short port) |
Set the hostname and port of the remote connection. More... | |
const std::string & | getRemoteHost () const |
Get the name of the remote host. More... | |
unsigned short | getRemotePort () const |
const std::string & | getRemoteUnixPath () const |
Get the name of the remote host. More... | |
void | setRemoteUnixPath (const std::string &unixPath) |
Set the pathname for the unix socket connection. More... | |
void | setRemoteSocketAddress (const nidas::util::SocketAddress &val) |
const nidas::util::SocketAddress & | getRemoteSocketAddress () throw (nidas::util::UnknownHostException) |
This method does a DNS lookup of the value of getRemoteHost(), and so it can throw an UnknownHostException. More... | |
void | fromDOMElement (const xercesc::DOMElement *) throw (nidas::util::InvalidParameterException) |
Initialize myself from a xercesc::DOMElement. More... | |
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 * | createSocket (const xercesc::DOMElement *) throw (nidas::util::InvalidParameterException) |
Create either a Socket or a McSocket from a DOMElement. More... | |
static IOChannel * | createIOChannel (const xercesc::DOMElement *node) throw (nidas::util::InvalidParameterException) |
static const XMLCh * | getNamespaceURI () |
Protected Member Functions | |
Socket (const Socket &x) | |
Copy constructor. More... | |
Private Member Functions | |
Socket & | operator= (const Socket &) |
No assignment. More... | |
Private Attributes | |
nidas::util::auto_ptr < nidas::util::SocketAddress > | _remoteSockAddr |
std::string | _remoteHost |
unsigned short | _remotePort |
std::string | _unixPath |
nidas::util::Socket * | _nusocket |
std::string | _name |
IOChannelRequester * | _iochanRequester |
ConnectionThread * | _connectionThread |
bool | _firstRead |
bool | _newInput |
int | _keepAliveIdleSecs |
bool | _nonBlocking |
nidas::util::Mutex | _connectionMutex |
enum McSocketRequest | _requestType |
Socket::Socket | ( | ) |
Socket::Socket | ( | nidas::util::Socket * | sock | ) |
Constructor from a connected nidas::util::Socket.
sock | Pointer to the connected nidas::util::Socket. Socket will own the pointer and will delete it it its destructor. |
References _keepAliveIdleSecs, _nonBlocking, _nusocket, _remoteHost, _remoteSockAddr, _unixPath, nidas::util::Inet4Address::getHostAddress(), nidas::util::Inet4SocketAddress::getInet4Address(), nidas::util::Socket::getKeepAliveIdleSecs(), nidas::util::Socket::isNonBlocking(), setRemoteHostPort(), setRemoteUnixPath(), and nidas::util::UnixSocketAddress::toString().
Socket::~Socket | ( | ) |
|
virtual |
|
virtual |
Implements nidas::core::IOChannel.
References _nusocket, and nidas::util::Socket::close().
Referenced by WriterThread::run(), and ~Socket().
|
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 _firstRead, _keepAliveIdleSecs, _newInput, _nonBlocking, _nusocket, nidas::util::Socket::connect(), nidas::util::SocketAddress::getConstSockAddrPtr(), nidas::util::SocketAddress::getFamily(), nidas::util::Socket::getInterfaces(), nidas::util::Socket::getLocalSocketAddress(), getRemoteSocketAddress(), nidas::util::Socket::getRemoteSocketAddress(), nidas::core::IOChannel::setConnectionInfo(), nidas::util::Socket::setKeepAliveIdleSecs(), setName(), nidas::util::Socket::setNonBlocking(), and nidas::util::SocketAddress::toAddressString().
|
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(), 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().
|
static |
Create either a Socket or a McSocket from a DOMElement.
References nidas::core::XDOMElement::getAttributeValue(), and Socket().
Referenced by nidas::core::IOChannel::createIOChannel().
|
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(), getName(), port, setKeepAliveIdleSecs(), setNonBlocking(), setRemoteHostPort(), setRemoteUnixPath(), nidas::util::Exception::what(), and WLOG.
|
virtual |
Return suggested buffer length.
Reimplemented from nidas::core::IOChannel.
References _nusocket, and nidas::util::Socket::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::Socket::getFd().
|
inline |
References _nusocket, and nidas::util::Socket::getInterfaces().
|
inline |
Return getKeepAliveIdleSecs() on underlying socket.
References _keepAliveIdleSecs, _nusocket, and nidas::util::Socket::getKeepAliveIdleSecs().
|
inlinevirtual |
Implements nidas::core::IOChannel.
References _name.
Referenced by fromDOMElement(), nidas::core::ServerSocket::fromDOMElement(), and nidas::core::Socket::ConnectionThread::run().
|
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().
|
inline |
Get the name of the remote host.
References _remoteHost.
n_u::Inet4Address Socket::getRemoteInet4Address | ( | ) |
|
inline |
References _remotePort.
const n_u::SocketAddress & Socket::getRemoteSocketAddress | ( | ) | ||
throw | ( | nidas::util::UnknownHostException | ||
) |
This method does a DNS lookup of the value of getRemoteHost(), and so it can throw an UnknownHostException.
This is different behaviour from the the nidas::util::Socket::getRemoteSocketAddress() method, which does not throw an exception.
References _remoteHost, _remotePort, _remoteSockAddr, nidas::util::Inet4Address::getByName(), getRemoteUnixPath(), setName(), and setRemoteSocketAddress().
Referenced by connect(), getRemoteInet4Address(), WriterThread::run(), and nidas::core::ServerSocket::ConnectionThread::run().
|
inline |
|
inlinevirtual |
Reimplemented from nidas::core::IOChannel.
References _requestType.
|
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.
References _newInput.
|
inlinevirtual |
Return isNonBlocking() of underlying socket.
Implements nidas::core::IOChannel.
References _nonBlocking, _nusocket, and nidas::util::Socket::isNonBlocking().
|
inlinevirtual |
Do the actual hardware read.
Implements nidas::core::IOChannel.
References _firstRead, _newInput, _nusocket, len, and nidas::util::Socket::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.
References nidas::util::Exception::what().
|
inlinevirtualinherited |
|
inlinevirtualinherited |
What DSM is this IOChannel connected to?
Referenced by nidas::core::SampleOutputBase::fromDOMElement(), nidas::core::SampleOutputBase::SampleOutputBase(), and nidas::core::SampleOutputBase::setIOChannel().
|
inline |
Do setKeepAliveIdleSecs(int secs) on underlying socket.
References _keepAliveIdleSecs, _nusocket, and nidas::util::Socket::setKeepAliveIdleSecs().
Referenced by fromDOMElement(), and nidas::core::ServerSocket::fromDOMElement().
|
inlinevirtual |
Implements nidas::core::IOChannel.
References _name.
Referenced by connect(), nidas::core::ServerSocket::fromDOMElement(), getRemoteSocketAddress(), and Socket().
|
inlinevirtual |
Do setNonBlocking(val) on underlying socket.
Implements nidas::core::IOChannel.
References _nonBlocking, _nusocket, and nidas::util::Socket::setNonBlocking().
Referenced by nidas::core::ServerSocket::connect(), fromDOMElement(), nidas::core::ServerSocket::fromDOMElement(), and WriterThread::run().
void Socket::setRemoteHostPort | ( | 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 _remoteHost, _remotePort, and port.
Referenced by fromDOMElement(), and Socket().
void Socket::setRemoteSocketAddress | ( | const nidas::util::SocketAddress & | val | ) |
References _remoteSockAddr, and nidas::util::SocketAddress::clone().
Referenced by getRemoteSocketAddress().
void Socket::setRemoteUnixPath | ( | const std::string & | unixPath | ) |
Set the pathname for the unix socket connection.
References _unixPath.
Referenced by fromDOMElement(), and Socket().
|
inlinevirtual |
Reimplemented from nidas::core::IOChannel.
References _requestType.
Referenced by nidas::core::McSocket::connect(), and nidas::core::McSocket::connected().
|
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, nidas::util::UTime::format(), len, and nidas::util::Socket::send().
|
inlinevirtual |
Do the actual hardware write.
Implements nidas::core::IOChannel.
References _nusocket, and nidas::util::Socket::send().
|
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 ~Socket().
|
private |
Referenced by ~Socket().
|
private |
|
private |
Referenced by connect(), getKeepAliveIdleSecs(), setKeepAliveIdleSecs(), and Socket().
|
private |
Referenced by connect(), isNewInput(), and read().
|
private |
Referenced by connect(), isNonBlocking(), setNonBlocking(), and Socket().
|
private |
Referenced by close(), connect(), getBufferSize(), getFd(), getInterfaces(), getKeepAliveIdleSecs(), isNonBlocking(), read(), setKeepAliveIdleSecs(), setNonBlocking(), Socket(), write(), and ~Socket().
|
private |
Referenced by getRemoteHost(), getRemoteSocketAddress(), setRemoteHostPort(), and Socket().
|
private |
Referenced by getRemotePort(), getRemoteSocketAddress(), and setRemoteHostPort().
|
private |
Referenced by getRemoteSocketAddress(), setRemoteSocketAddress(), and Socket().
|
private |
Referenced by getRequestType(), and setRequestType().
|
private |
Referenced by getRemoteUnixPath(), setRemoteUnixPath(), and Socket().