nidas  v1.2-1520
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | 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. More...
 
 Socket (nidas::util::Socket *sock)
 Constructor from a connected nidas::util::Socket. More...
 
 ~Socket ()
 
Socketclone () 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...
 
IOChannelconnect () 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::SocketAddressgetRemoteSocketAddress () 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 ConnectionInfogetConnectionInfo () 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 DSMConfiggetDSMConfig () 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 IOChannelcreateSocket (const xercesc::DOMElement *) throw (nidas::util::InvalidParameterException)
 Create either a Socket or a McSocket from a DOMElement. More...
 
static IOChannelcreateIOChannel (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

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

Detailed Description

Implementation of an IOChannel, over a Socket.

Constructor & Destructor Documentation

Socket::Socket ( )

Constructor.

References setName().

Referenced by clone(), and createSocket().

Socket::Socket ( nidas::util::Socket sock)
Socket::~Socket ( )
Socket::Socket ( const Socket x)
protected

Copy constructor.

References _nusocket.

Member Function Documentation

Socket * Socket::clone ( ) const
virtual

Derived classes must provide clone.

Implements nidas::core::IOChannel.

References Socket().

void Socket::close ( )
throw (nidas::util::IOException
)
virtual
IOChannel * Socket::connect ( )
throw (nidas::util::IOException,
nidas::util::UnknownHostException
)
virtual
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.

Reimplemented in nidas::core::FileSet.

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

IOChannel * IOChannel::createIOChannel ( const xercesc::DOMElement *  node)
throw (nidas::util::InvalidParameterException
)
staticinherited
IOChannel * Socket::createSocket ( const xercesc::DOMElement *  node)
throw (nidas::util::InvalidParameterException
)
static

Create either a Socket or a McSocket from a DOMElement.

References nidas::core::XDOMElement::getAttributeValue(), and Socket().

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

virtual void nidas::core::IOChannel::flush ( )
throw (nidas::util::IOException
)
inlinevirtualinherited
void Socket::fromDOMElement ( const xercesc::DOMElement *  )
throw (nidas::util::InvalidParameterException
)
virtual
size_t Socket::getBufferSize ( ) const
throw (
)
virtual

Return suggested buffer length.

Reimplemented from nidas::core::IOChannel.

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

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.

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

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

What DSM is this IOChannel connected to? May be NULL.

Referenced by nidas::core::FileSet::setDir(), and nidas::core::FileSet::setFileName().

int nidas::core::Socket::getFd ( ) const
inlinevirtual
std::list<nidas::util::Inet4NetworkInterface> nidas::core::Socket::getInterfaces ( ) const
throw (nidas::util::IOException
)
inline
int nidas::core::Socket::getKeepAliveIdleSecs ( ) const
throw (nidas::util::IOException
)
inline
const std::string& nidas::core::Socket::getName ( ) const
inlinevirtual
static const XMLCh* nidas::core::DOMable::getNamespaceURI ( )
inlinestaticinherited
virtual int nidas::core::IOChannel::getReconnectDelaySecs ( ) const
inlinevirtualinherited
const std::string& nidas::core::Socket::getRemoteHost ( ) const
inline

Get the name of the remote host.

References _remoteHost.

n_u::Inet4Address Socket::getRemoteInet4Address ( )
unsigned short nidas::core::Socket::getRemotePort ( ) const
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().

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

Get the name of the remote host.

References _unixPath.

Referenced by getRemoteSocketAddress().

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

Reimplemented from nidas::core::IOChannel.

References _requestType.

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.

bool nidas::core::Socket::isNonBlocking ( ) const
throw (nidas::util::IOException
)
inlinevirtual

Return isNonBlocking() of underlying socket.

Implements nidas::core::IOChannel.

References _nonBlocking, _nusocket, and nidas::util::Socket::isNonBlocking().

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

No assignment.

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

Do the actual hardware read.

Implements nidas::core::IOChannel.

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

void Socket::requestConnection ( IOChannelRequester )
throw (nidas::util::IOException
)
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().

virtual void nidas::core::IOChannel::setConnectionInfo ( const ConnectionInfo val)
inlinevirtualinherited
virtual void nidas::core::IOChannel::setDSMConfig ( const DSMConfig val)
inlinevirtualinherited
void nidas::core::Socket::setKeepAliveIdleSecs ( int  val)
throw (nidas::util::IOException
)
inline
void nidas::core::Socket::setName ( const std::string &  val)
inlinevirtual
void nidas::core::Socket::setNonBlocking ( bool  val)
throw (nidas::util::IOException
)
inlinevirtual
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)
void Socket::setRemoteUnixPath ( const std::string &  unixPath)

Set the pathname for the unix socket connection.

References _unixPath.

Referenced by fromDOMElement(), and Socket().

void nidas::core::Socket::setRequestType ( enum McSocketRequest  val)
inlinevirtual
xercesc::DOMElement * DOMable::toDOMElement ( xercesc::DOMElement *  node,
bool  complete 
) const
throw (xercesc::DOMException
)
virtualinherited
xercesc::DOMElement * DOMable::toDOMParent ( xercesc::DOMElement *  parent,
bool  complete 
) const
throw (xercesc::DOMException
)
virtualinherited
size_t nidas::core::Socket::write ( const void *  buf,
size_t  len 
)
throw (nidas::util::IOException
)
inlinevirtual

Do the actual hardware write.

Implements nidas::core::IOChannel.

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

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

Do the actual hardware write.

Implements nidas::core::IOChannel.

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

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

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

Referenced by ~Socket().

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

Referenced by ~Socket().

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

Referenced by connect(), and read().

IOChannelRequester* nidas::core::Socket::_iochanRequester
private
int nidas::core::Socket::_keepAliveIdleSecs
private
std::string nidas::core::Socket::_name
private

Referenced by getName(), and setName().

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

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

bool nidas::core::Socket::_nonBlocking
private
nidas::util::Socket* nidas::core::Socket::_nusocket
private
std::string nidas::core::Socket::_remoteHost
private
unsigned short nidas::core::Socket::_remotePort
private
nidas::util::auto_ptr<nidas::util::SocketAddress> nidas::core::Socket::_remoteSockAddr
private
enum McSocketRequest nidas::core::Socket::_requestType
private

Referenced by getRequestType(), and setRequestType().

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

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