nidas v1.2.3
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
nidas::core::Socket Class Reference

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

#include <Socket.h>

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

Classes

class  ConnectionThread
 

Public Member Functions

 Socket ()
 Constructor.
 
 Socket (nidas::util::Socket *sock)
 Constructor from a connected nidas::util::Socket.
 
 ~Socket ()
 
Socketclone () const
 Derived classes must provide clone.
 
void requestConnection (IOChannelRequester *service)
 
IOChannelconnect ()
 
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::Inet4NetworkInterfacegetInterfaces () 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::SocketAddressgetRemoteSocketAddress ()
 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 ConnectionInfogetConnectionInfo () 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 DSMConfiggetDSMConfig () 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 IOChannelcreateSocket (const xercesc::DOMElement *)
 Create either a Socket or a McSocket from a DOMElement.
 
static IOChannelcreateIOChannel (const xercesc::DOMElement *node)
 
static const XMLChgetNamespaceURI ()
 

Protected Member Functions

 Socket (const Socket &x)
 Copy constructor.
 

Private Member Functions

Socketoperator= (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 XMLChnamespaceURI = 0
 

Detailed Description

Implementation of an IOChannel, over a Socket.

Constructor & Destructor Documentation

◆ Socket() [1/3]

Socket::Socket ( )

Constructor.

References setName().

Referenced by clone(), and createSocket().

◆ Socket() [2/3]

Socket::Socket ( nidas::util::Socket * sock)

◆ ~Socket()

Socket::~Socket ( )

◆ Socket() [3/3]

Socket::Socket ( const Socket & x)
protected

Copy constructor.

References nidas::core::getSample().

Member Function Documentation

◆ addSampleTag()

void IOChannel::addSampleTag ( const nidas::core::SampleTag * )
virtualinherited

The special NetcdfRPCChannel subclass needs a way to add a SampleTag to the IOChannel through a virtual base class.

This method does nothing and serves no purpose except for that class.

◆ clone()

Socket * Socket::clone ( ) const
virtual

Derived classes must provide clone.

Implements nidas::core::IOChannel.

References Socket().

◆ close()

void Socket::close ( )
virtual

◆ connect()

IOChannel * Socket::connect ( )
virtual

◆ createFile()

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.
Exceptions
nidas::util::IOException

Reimplemented in nidas::core::FileSet.

References nidas::core::getSample().

Referenced by nidas::core::IOStream::createFile(), and nidas::core::SampleOutputBase::createNextFile().

◆ createIOChannel()

IOChannel * IOChannel::createIOChannel ( const xercesc::DOMElement * node)
staticinherited

◆ createSocket()

IOChannel * Socket::createSocket ( const xercesc::DOMElement * node)
static

Create either a Socket or a McSocket from a DOMElement.

Exceptions
nidas::util::InvalidParameterException

References nidas::core::getSample(), and Socket().

Referenced by nidas::core::IOChannel::createIOChannel().

◆ flush()

virtual void nidas::core::IOChannel::flush ( )
inlinevirtualinherited

Default flush implementation does nothing.

Exceptions
nidas::util::IOException

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

◆ fromDOMElement()

void Socket::fromDOMElement ( const xercesc::DOMElement * node)
virtual

◆ getBufferSize()

size_t Socket::getBufferSize ( ) const
throw ( )
virtual

Return suggested buffer length.

Reimplemented from nidas::core::IOChannel.

References _nusocket, nidas::util::Socket::getReceiveBufferSize(), and nidas::core::getSample().

◆ getConnectionInfo()

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.

References nidas::core::IOChannel::_conInfo.

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

◆ getDSMConfig()

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

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().

◆ getFd()

int nidas::core::Socket::getFd ( ) const
inlinevirtual

◆ getInterfaces()

std::list< nidas::util::Inet4NetworkInterface > nidas::core::Socket::getInterfaces ( ) const
inline

◆ getKeepAliveIdleSecs()

int nidas::core::Socket::getKeepAliveIdleSecs ( ) const
inline

◆ getName()

const std::string & nidas::core::Socket::getName ( ) const
inlinevirtual

◆ getNamespaceURI()

static const XMLCh * nidas::core::DOMable::getNamespaceURI ( )
inlinestaticinherited

◆ getReconnectDelaySecs()

virtual int nidas::core::IOChannel::getReconnectDelaySecs ( ) const
inlinevirtualinherited

◆ getRemoteHost()

const std::string & nidas::core::Socket::getRemoteHost ( ) const
inline

Get the name of the remote host.

References _remoteHost.

◆ getRemoteInet4Address()

n_u::Inet4Address Socket::getRemoteInet4Address ( )

◆ getRemotePort()

unsigned short nidas::core::Socket::getRemotePort ( ) const
inline

References _remotePort.

◆ getRemoteSocketAddress()

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.

Exceptions
nidas::util::UnknownHostException

References _remoteHost, _remotePort, _remoteSockAddr, getRemoteUnixPath(), nidas::core::getSample(), setName(), and setRemoteSocketAddress().

Referenced by connect(), getRemoteInet4Address(), and WriterThread::run().

◆ getRemoteUnixPath()

const std::string & nidas::core::Socket::getRemoteUnixPath ( ) const
inline

Get the name of the remote host.

References _unixPath.

Referenced by getRemoteSocketAddress().

◆ getRequestType()

enum McSocketRequest nidas::core::Socket::getRequestType ( ) const
inlinevirtual

Reimplemented from nidas::core::IOChannel.

References _requestType.

◆ isNewInput()

virtual bool nidas::core::Socket::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.

References _newInput.

◆ isNonBlocking()

bool nidas::core::Socket::isNonBlocking ( ) const
inlinevirtual

◆ operator=()

Socket & nidas::core::Socket::operator= ( const Socket & )
private

No assignment.

◆ read()

size_t nidas::core::Socket::read ( void * buf,
size_t len )
inlinevirtual

Do the actual hardware read.

Exceptions
nidas::util::IOException

Implements nidas::core::IOChannel.

References _firstRead, _newInput, _nusocket, len, and nidas::util::Socket::recv().

◆ requestConnection()

void Socket::requestConnection ( IOChannelRequester * service)
virtual

◆ setConnectionInfo()

virtual void nidas::core::IOChannel::setConnectionInfo ( const ConnectionInfo & val)
inlinevirtualinherited

◆ setDSMConfig()

virtual void nidas::core::IOChannel::setDSMConfig ( const DSMConfig * val)
inlinevirtualinherited

◆ setKeepAliveIdleSecs()

void nidas::core::Socket::setKeepAliveIdleSecs ( int val)
inline

◆ setName()

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

◆ setNonBlocking()

void nidas::core::Socket::setNonBlocking ( bool val)
inlinevirtual

◆ setRemoteHostPort()

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, nidas::core::getSample(), and port.

Referenced by fromDOMElement(), and Socket().

◆ setRemoteSocketAddress()

void Socket::setRemoteSocketAddress ( const nidas::util::SocketAddress & val)

References _remoteSockAddr.

Referenced by getRemoteSocketAddress().

◆ setRemoteUnixPath()

void Socket::setRemoteUnixPath ( const std::string & unixPath)

Set the pathname for the unix socket connection.

References _unixPath, and nidas::core::getSample().

Referenced by fromDOMElement(), and Socket().

◆ setRequestType()

void nidas::core::Socket::setRequestType ( enum McSocketRequest val)
inlinevirtual

Reimplemented from nidas::core::IOChannel.

References _requestType, and nidas::core::getSample().

◆ toDOMElement()

xercesc::DOMElement * DOMable::toDOMElement ( xercesc::DOMElement * node,
bool complete ) const
virtualinherited

◆ toDOMParent()

xercesc::DOMElement * DOMable::toDOMParent ( xercesc::DOMElement * parent,
bool complete ) const
virtualinherited

Create a DOMElement and append it to the parent.

Exceptions
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.

◆ write() [1/2]

size_t nidas::core::Socket::write ( const struct iovec * iov,
int iovcnt )
inlinevirtual

Do the actual hardware write.

Exceptions
nidas::util::IOException

Implements nidas::core::IOChannel.

References _nusocket, nidas::core::getSample(), and nidas::util::Socket::send().

◆ write() [2/2]

size_t nidas::core::Socket::write ( const void * buf,
size_t len )
inlinevirtual

Do the actual hardware write.

Exceptions
nidas::util::IOException

Implements nidas::core::IOChannel.

References _nusocket, nidas::util::UTime::format(), len, and nidas::util::Socket::send().

◆ writeNidasHeader()

virtual bool nidas::core::IOChannel::writeNidasHeader ( ) const
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().

Member Data Documentation

◆ _conInfo

ConnectionInfo nidas::core::IOChannel::_conInfo
privateinherited

◆ _connectionMutex

nidas::util::Mutex nidas::core::Socket::_connectionMutex
private

Referenced by requestConnection(), and ~Socket().

◆ _connectionThread

ConnectionThread* nidas::core::Socket::_connectionThread
private

Referenced by requestConnection(), and ~Socket().

◆ _dsm

const DSMConfig* nidas::core::IOChannel::_dsm
privateinherited

◆ _firstRead

bool nidas::core::Socket::_firstRead
private

Referenced by connect(), and read().

◆ _iochanRequester

IOChannelRequester* nidas::core::Socket::_iochanRequester
private

Referenced by requestConnection().

◆ _keepAliveIdleSecs

int nidas::core::Socket::_keepAliveIdleSecs
private

◆ _name

std::string nidas::core::Socket::_name
private

Referenced by getName(), and setName().

◆ _newInput

bool nidas::core::Socket::_newInput
private

Referenced by connect(), isNewInput(), and read().

◆ _nonBlocking

bool nidas::core::Socket::_nonBlocking
private

◆ _nusocket

nidas::util::Socket* nidas::core::Socket::_nusocket
private

◆ _remoteHost

std::string nidas::core::Socket::_remoteHost
private

◆ _remotePort

unsigned short nidas::core::Socket::_remotePort
private

◆ _remoteSockAddr

nidas::util::auto_ptr<nidas::util::SocketAddress> nidas::core::Socket::_remoteSockAddr
private

◆ _requestType

enum McSocketRequest nidas::core::Socket::_requestType
private

Referenced by getRequestType(), and setRequestType().

◆ _unixPath

std::string nidas::core::Socket::_unixPath
private

◆ namespaceURI

XMLCh * DOMable::namespaceURI = 0
staticprivateinherited

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