nidas v1.2.3
|
Implementation of an IOChannel, over a Socket. More...
#include <Socket.h>
Classes | |
class | ConnectionThread |
Public Member Functions | |
Socket () | |
Constructor. | |
Socket (nidas::util::Socket *sock) | |
Constructor from a connected nidas::util::Socket. | |
~Socket () | |
Socket * | clone () const |
Derived classes must provide clone. | |
void | requestConnection (IOChannelRequester *service) |
IOChannel * | connect () |
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. | |
void | setRequestType (enum McSocketRequest val) |
enum McSocketRequest | getRequestType () const |
void | setKeepAliveIdleSecs (int val) |
Do setKeepAliveIdleSecs(int secs) on underlying socket. | |
int | getKeepAliveIdleSecs () const |
Return getKeepAliveIdleSecs() on underlying socket. | |
std::list< nidas::util::Inet4NetworkInterface > | getInterfaces () const |
void | setNonBlocking (bool val) |
Do setNonBlocking(val) on underlying socket. | |
bool | isNonBlocking () const |
Return isNonBlocking() of underlying socket. | |
size_t | getBufferSize () const throw () |
Return suggested buffer length. | |
size_t | read (void *buf, size_t len) |
Do the actual hardware read. | |
size_t | write (const void *buf, size_t len) |
Do the actual hardware write. | |
size_t | write (const struct iovec *iov, int iovcnt) |
Do the actual hardware write. | |
void | close () |
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. | |
const std::string & | getRemoteHost () const |
Get the name of the remote host. | |
unsigned short | getRemotePort () const |
const std::string & | getRemoteUnixPath () const |
Get the name of the remote host. | |
void | setRemoteUnixPath (const std::string &unixPath) |
Set the pathname for the unix socket connection. | |
void | setRemoteSocketAddress (const nidas::util::SocketAddress &val) |
const nidas::util::SocketAddress & | getRemoteSocketAddress () |
This method does a DNS lookup of the value of getRemoteHost(), and so it can throw an UnknownHostException. | |
void | fromDOMElement (const xercesc::DOMElement *) |
virtual int | getReconnectDelaySecs () const |
virtual const ConnectionInfo & | getConnectionInfo () const |
What is the IP address of the host at the other end of the connection. | |
virtual void | setConnectionInfo (const ConnectionInfo &val) |
virtual void | flush () |
Default flush implementation does nothing. | |
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. | |
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. | |
virtual void | setDSMConfig (const DSMConfig *val) |
What DSM is this IOChannel connected to? | |
virtual const DSMConfig * | getDSMConfig () const |
What DSM is this IOChannel connected to? May be NULL. | |
virtual void | addSampleTag (const nidas::core::SampleTag *) |
The special NetcdfRPCChannel subclass needs a way to add a SampleTag to the IOChannel through a virtual base class. | |
virtual xercesc::DOMElement * | toDOMParent (xercesc::DOMElement *parent, bool complete) const |
Create a DOMElement and append it to the parent. | |
virtual xercesc::DOMElement * | toDOMElement (xercesc::DOMElement *node, bool complete) const |
Add my content into a DOMElement. | |
Static Public Member Functions | |
static IOChannel * | createSocket (const xercesc::DOMElement *) |
Create either a Socket or a McSocket from a DOMElement. | |
static IOChannel * | createIOChannel (const xercesc::DOMElement *node) |
static const XMLCh * | getNamespaceURI () |
Protected Member Functions | |
Socket (const Socket &x) | |
Copy constructor. | |
Private Member Functions | |
Socket & | operator= (const Socket &) |
No assignment. | |
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 |
const DSMConfig * | _dsm |
ConnectionInfo | _conInfo |
Static Private Attributes | |
static XMLCh * | namespaceURI = 0 |
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::Socket::getKeepAliveIdleSecs(), nidas::core::getSample(), nidas::util::Socket::isNonBlocking(), setRemoteHostPort(), and setRemoteUnixPath().
Socket::~Socket | ( | ) |
Copy constructor.
References nidas::core::getSample().
|
virtualinherited |
|
virtual |
|
virtual |
nidas::util::IOException |
Implements nidas::core::IOChannel.
References _nusocket, and nidas::util::Socket::close().
Referenced by WriterThread::run(), and ~Socket().
|
virtual |
Implements nidas::core::IOChannel.
References _firstRead, _keepAliveIdleSecs, _newInput, _nonBlocking, _nusocket, nidas::util::Socket::connect(), nidas::util::Inet4SocketAddress::getInet4Address(), nidas::util::Socket::getInterfaces(), nidas::util::Socket::getLocalSocketAddress(), getRemoteSocketAddress(), nidas::util::Socket::getRemoteSocketAddress(), nidas::core::getSample(), nidas::core::IOChannel::setConnectionInfo(), nidas::util::Socket::setKeepAliveIdleSecs(), setName(), and nidas::util::Socket::setNonBlocking().
|
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. |
nidas::util::IOException |
Reimplemented in nidas::core::FileSet.
References nidas::core::getSample().
Referenced by nidas::core::IOStream::createFile(), and nidas::core::SampleOutputBase::createNextFile().
nidas::util::InvalidParameterException |
References nidas::core::DOMObjectFactory::createObject(), createSocket(), and nidas::core::getSample().
Referenced by nidas::core::DSMService::fromDOMElement(), nidas::core::SampleOutputBase::fromDOMElement(), and nidas::dynld::SampleInputStream::fromDOMElement().
Create either a Socket or a McSocket from a DOMElement.
nidas::util::InvalidParameterException |
References nidas::core::getSample(), and Socket().
Referenced by nidas::core::IOChannel::createIOChannel().
Default flush implementation does nothing.
nidas::util::IOException |
Referenced by nidas::core::IOStream::flush().
nidas::util::InvalidParameterException |
Implements nidas::core::DOMable.
References getName(), nidas::core::getSample(), port, setKeepAliveIdleSecs(), setNonBlocking(), setRemoteHostPort(), setRemoteUnixPath(), and WLOG.
|
virtual |
Return suggested buffer length.
Reimplemented from nidas::core::IOChannel.
References _nusocket, nidas::util::Socket::getReceiveBufferSize(), and nidas::core::getSample().
|
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.
References nidas::core::IOChannel::_conInfo.
Referenced by nidas::dynld::SampleInputStream::setIOChannel().
What DSM is this IOChannel connected to? May be NULL.
References nidas::core::IOChannel::_dsm.
Referenced by nidas::core::FileSet::setDir(), and nidas::core::FileSet::setFileName().
|
inlinevirtual |
Implements nidas::core::IOChannel.
References _nusocket, and nidas::util::Socket::getFd().
|
inline |
nidas::util::IOException |
References _nusocket, and nidas::util::Socket::getInterfaces().
|
inline |
Return getKeepAliveIdleSecs() on underlying socket.
nidas::util::IOException |
References _keepAliveIdleSecs, _nusocket, and nidas::util::Socket::getKeepAliveIdleSecs().
|
inlinevirtual |
Implements nidas::core::IOChannel.
References _name.
Referenced by fromDOMElement(), nidas::core::ServerSocket::fromDOMElement(), requestConnection(), and nidas::core::Socket::ConnectionThread::run().
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::Datasets::toDOMParent(), nidas::core::ProjectConfig::toDOMParent(), nidas::core::ProjectConfigs::toDOMParent(), nidas::core::DSMConfig::toDOMParent(), nidas::core::DSMSensor::toDOMParent(), nidas::core::Project::toDOMParent(), nidas::core::SampleTag::toDOMParent(), nidas::core::Site::toDOMParent(), nidas::core::ServerSocket::toDOMParent(), nidas::core::Variable::toDOMParent(), nidas::core::Datasets::writeXML(), and nidas::core::ProjectConfigs::writeXML().
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 | ( | ) |
References getRemoteSocketAddress(), and LOG_WARNING.
References _remotePort.
const n_u::SocketAddress & Socket::getRemoteSocketAddress | ( | ) |
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.
nidas::util::UnknownHostException |
References _remoteHost, _remotePort, _remoteSockAddr, getRemoteUnixPath(), nidas::core::getSample(), setName(), and setRemoteSocketAddress().
Referenced by connect(), getRemoteInet4Address(), and WriterThread::run().
|
inline |
|
inlinevirtual |
Reimplemented from nidas::core::IOChannel.
References _requestType.
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.
nidas::util::IOException |
Implements nidas::core::IOChannel.
References _nonBlocking, _nusocket, and nidas::util::Socket::isNonBlocking().
Do the actual hardware read.
nidas::util::IOException |
Implements nidas::core::IOChannel.
References _firstRead, _newInput, _nusocket, len, and nidas::util::Socket::recv().
|
virtual |
nidas::util::IOException |
Implements nidas::core::IOChannel.
References _connectionMutex, _connectionThread, _iochanRequester, getName(), nidas::core::getSample(), and nidas::util::Thread::start().
|
inlinevirtualinherited |
References nidas::core::IOChannel::_conInfo, and nidas::core::getSample().
Referenced by connect().
What DSM is this IOChannel connected to?
References nidas::core::IOChannel::_dsm, and nidas::core::getSample().
Referenced by nidas::core::SampleOutputBase::SampleOutputBase(), and nidas::core::SampleOutputBase::setIOChannel().
Do setKeepAliveIdleSecs(int secs) on underlying socket.
nidas::util::IOException |
References _keepAliveIdleSecs, _nusocket, nidas::core::getSample(), and nidas::util::Socket::setKeepAliveIdleSecs().
Referenced by fromDOMElement(), and nidas::core::ServerSocket::fromDOMElement().
Implements nidas::core::IOChannel.
References _name, and nidas::core::getSample().
Referenced by connect(), nidas::core::ServerSocket::fromDOMElement(), getRemoteSocketAddress(), and Socket().
Do setNonBlocking(val) on underlying socket.
nidas::util::IOException |
Implements nidas::core::IOChannel.
References _nonBlocking, _nusocket, nidas::core::getSample(), and nidas::util::Socket::setNonBlocking().
Referenced by fromDOMElement(), nidas::core::ServerSocket::fromDOMElement(), and WriterThread::run().
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, nidas::core::getSample(), and port.
Referenced by fromDOMElement(), and Socket().
void Socket::setRemoteSocketAddress | ( | const nidas::util::SocketAddress & | val | ) |
References _remoteSockAddr.
Referenced by getRemoteSocketAddress().
Set the pathname for the unix socket connection.
References _unixPath, and nidas::core::getSample().
Referenced by fromDOMElement(), and Socket().
|
inlinevirtual |
Reimplemented from nidas::core::IOChannel.
References _requestType, and nidas::core::getSample().
|
virtualinherited |
Add my content into a DOMElement.
xercesc::DOMException |
Reimplemented in nidas::core::DSMConfig, nidas::core::DSMSensor, nidas::core::Project, nidas::core::SampleTag, nidas::core::Site, nidas::core::ServerSocket, and nidas::core::Variable.
Referenced by nidas::core::ServerSocket::toDOMParent().
|
virtualinherited |
Create a DOMElement and append it to the parent.
xercesc::DOMException |
Reimplemented in nidas::core::DSMConfig, nidas::core::DSMSensor, nidas::core::Project, nidas::core::SampleTag, nidas::core::Site, nidas::core::ServerSocket, and nidas::core::Variable.
Do the actual hardware write.
nidas::util::IOException |
Implements nidas::core::IOChannel.
References _nusocket, nidas::core::getSample(), and nidas::util::Socket::send().
Do the actual hardware write.
nidas::util::IOException |
Implements nidas::core::IOChannel.
References _nusocket, nidas::util::UTime::format(), len, and nidas::util::Socket::send().
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().
|
privateinherited |
|
private |
Referenced by requestConnection(), and ~Socket().
|
private |
Referenced by requestConnection(), and ~Socket().
|
private |
Referenced by requestConnection().
|
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(), write(), and ~Socket().
|
private |
Referenced by getRemoteHost(), getRemoteSocketAddress(), setRemoteHostPort(), and Socket().
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().
|
staticprivateinherited |
Referenced by nidas::core::DOMable::getNamespaceURI().