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::ServerSocket Class Reference

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

#include <Socket.h>

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

Classes

class  ConnectionThread
 

Public Member Functions

 ServerSocket ()
 Constructor. More...
 
 ServerSocket (const nidas::util::SocketAddress &addr)
 Constructor. More...
 
 ~ServerSocket ()
 
ServerSocketclone () 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)
 Establish a connection. More...
 
const std::string & getName () const
 
void setName (const std::string &val)
 
int getFd () const
 
void setKeepAliveIdleSecs (int val) throw (nidas::util::IOException)
 Set the value of keepAliveIdleSecs. More...
 
int getKeepAliveIdleSecs () const throw (nidas::util::IOException)
 Return keepAliveIdleSecs for this ServerSocket. More...
 
void setNonBlocking (bool val) throw (nidas::util::IOException)
 The blocking flag that will be set on accepted connections. More...
 
bool isNonBlocking () const throw (nidas::util::IOException)
 
size_t read (void *, size_t) throw (nidas::util::IOException)
 ServerSocket will never be called to do an actual read. More...
 
size_t write (const void *, size_t) throw (nidas::util::IOException)
 ServerSocket should never be called to do an actual write. More...
 
size_t write (const struct iovec *, int) throw (nidas::util::IOException)
 ServerSocket should never be called to do an actual write. More...
 
void close () throw (nidas::util::IOException)
 
void fromDOMElement (const xercesc::DOMElement *) throw (nidas::util::InvalidParameterException)
 Initialize myself from a xercesc::DOMElement. More...
 
xercesc::DOMElement * toDOMParent (xercesc::DOMElement *parent, bool complete) const throw (xercesc::DOMException)
 Create a DOMElement and append it to the parent. More...
 
xercesc::DOMElement * toDOMElement (xercesc::DOMElement *node, bool complete) const throw (xercesc::DOMException)
 Add my content into a DOMElement. More...
 
virtual void setRequestType (enum McSocketRequest)
 
virtual enum McSocketRequest getRequestType () const
 
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...
 
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 size_t getBufferSize () const throw ()
 Return suggested buffer length. More...
 
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...
 

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

 ServerSocket (const ServerSocket &x)
 Copy constructor. More...
 

Private Member Functions

ServerSocketoperator= (const ServerSocket &)
 No assignment. More...
 

Private Attributes

nidas::util::auto_ptr
< nidas::util::SocketAddress
_localSockAddr
 
std::string _name
 
nidas::util::ServerSocket_servSock
 
IOChannelRequester_iochanRequester
 
ConnectionThread_connectionThread
 
int _keepAliveIdleSecs
 
bool _nonBlocking
 

Detailed Description

Implementation of an IOChannel, over a ServerSocket.

Constructor & Destructor Documentation

ServerSocket::ServerSocket ( )

Constructor.

References _localSockAddr, and setName().

Referenced by clone().

ServerSocket::ServerSocket ( const nidas::util::SocketAddress addr)

Constructor.

References _localSockAddr, and setName().

ServerSocket::~ServerSocket ( )
ServerSocket::ServerSocket ( const ServerSocket x)
protected

Copy constructor.

Member Function Documentation

ServerSocket * ServerSocket::clone ( ) const
virtual

Derived classes must provide clone.

Implements nidas::core::IOChannel.

References ServerSocket().

void ServerSocket::close ( )
throw (nidas::util::IOException
)
virtual
IOChannel * ServerSocket::connect ( )
throw (nidas::util::IOException
)
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 _keepAliveIdleSecs, _localSockAddr, _nonBlocking, _servSock, nidas::util::ServerSocket::accept(), ILOG, nidas::util::Socket::setKeepAliveIdleSecs(), and nidas::core::Socket::setNonBlocking().

Referenced by nidas::dynld::raf::SyncServer::init().

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
static IOChannel* nidas::core::ServerSocket::createSocket ( const xercesc::DOMElement *  )
throw (nidas::util::InvalidParameterException
)
static

Create either a Socket or a McSocket from a DOMElement.

virtual void nidas::core::IOChannel::flush ( )
throw (nidas::util::IOException
)
inlinevirtualinherited
void ServerSocket::fromDOMElement ( const xercesc::DOMElement *  )
throw (nidas::util::InvalidParameterException
)
virtual
virtual size_t nidas::core::IOChannel::getBufferSize ( ) const
throw (
)
inlinevirtualinherited
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::ServerSocket::getFd ( ) const
inlinevirtual
int nidas::core::ServerSocket::getKeepAliveIdleSecs ( ) const
throw (nidas::util::IOException
)
inline

Return keepAliveIdleSecs for this ServerSocket.

References _keepAliveIdleSecs.

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

Implements nidas::core::IOChannel.

References _name.

static const XMLCh* nidas::core::DOMable::getNamespaceURI ( )
inlinestaticinherited
virtual int nidas::core::IOChannel::getReconnectDelaySecs ( ) const
inlinevirtualinherited
virtual enum McSocketRequest nidas::core::IOChannel::getRequestType ( ) const
inlinevirtualinherited
virtual bool nidas::core::IOChannel::isNewInput ( ) const
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 in nidas::core::UnixIOChannel, nidas::core::McSocketUDP, nidas::core::McSocket, nidas::core::Socket, nidas::core::DatagramSocket, and nidas::core::FileSet.

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

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

Implements nidas::core::IOChannel.

References _nonBlocking.

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

No assignment.

size_t nidas::core::ServerSocket::read ( void *  ,
size_t   
)
throw (nidas::util::IOException
)
inlinevirtual

ServerSocket will never be called to do an actual read.

Implements nidas::core::IOChannel.

void ServerSocket::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 ILOG, and 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::ServerSocket::setKeepAliveIdleSecs ( int  val)
throw (nidas::util::IOException
)
inline

Set the value of keepAliveIdleSecs.

This is set on each accepted socket connection. It does not pertain to the socket which is waiting for connections.

References _keepAliveIdleSecs.

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

Implements nidas::core::IOChannel.

References _name.

Referenced by ServerSocket().

void nidas::core::ServerSocket::setNonBlocking ( bool  val)
throw (nidas::util::IOException
)
inlinevirtual

The blocking flag that will be set on accepted connections.

The ServerSocket itself is always non-blocking.

Implements nidas::core::IOChannel.

References _nonBlocking.

virtual void nidas::core::IOChannel::setRequestType ( enum McSocketRequest  )
inlinevirtualinherited
xercesc::DOMElement * ServerSocket::toDOMElement ( xercesc::DOMElement *  node,
bool  complete 
) const
throw (xercesc::DOMException
)
virtual

Add my content into a DOMElement.

Reimplemented from nidas::core::DOMable.

xercesc::DOMElement * ServerSocket::toDOMParent ( xercesc::DOMElement *  parent,
bool  complete 
) const
throw (xercesc::DOMException
)
virtual

Create a DOMElement and append it to the parent.

Reimplemented from nidas::core::DOMable.

References nidas::core::DOMable::getNamespaceURI(), and nidas::core::DOMable::toDOMElement().

size_t nidas::core::ServerSocket::write ( const void *  ,
size_t   
)
throw (nidas::util::IOException
)
inlinevirtual

ServerSocket should never be called to do an actual write.

Implements nidas::core::IOChannel.

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

ServerSocket should never be called to do an actual write.

Implements nidas::core::IOChannel.

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

ConnectionThread* nidas::core::ServerSocket::_connectionThread
private

Referenced by close(), and ~ServerSocket().

IOChannelRequester* nidas::core::ServerSocket::_iochanRequester
private
int nidas::core::ServerSocket::_keepAliveIdleSecs
private
nidas::util::auto_ptr<nidas::util::SocketAddress> nidas::core::ServerSocket::_localSockAddr
private

Referenced by connect(), and ServerSocket().

std::string nidas::core::ServerSocket::_name
private

Referenced by getName(), and setName().

bool nidas::core::ServerSocket::_nonBlocking
private
nidas::util::ServerSocket* nidas::core::ServerSocket::_servSock
private

Referenced by close(), connect(), getFd(), and ~ServerSocket().


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