ZeusBase-Library  2.0.4
zeus::TAbstractSocket Class Referenceabstract

#include <AbstractSocket.h>

Inheritance diagram for zeus::TAbstractSocket:
zeus::TZObject zeus::IZUnknown zeus::TBluetoothServerSocket zeus::TBluetoothSocket zeus::TDatagramSocket zeus::TServerSocket zeus::TSocket

Public Member Functions

 TAbstractSocket (TIPAddress &rAddress)
 
 TAbstractSocket (const TString &rstrAddr, Uint uiPort)
 
 TAbstractSocket (Int iFD, struct sockaddr_in &rAddress)
 
virtual Retval connect ()=0
 
virtual Retval disconnect ()
 
TString getAddress () const
 
TString getHostName () const
 
Uint getPort () const
 
Int getReceiveBufferSize () const
 
Int getSendBufferSize () const
 
Int getSocketDescripitor () const
 
bool isConnected () const
 
bool isBlockable () const
 
bool isReUsable () const
 
bool isValid () const
 
void setBlockable (bool bMode)
 
void setReceiveBufferSize (Int iSize)
 
void setReUsable (bool bMode)
 
void setSendBufferSize (Int iSize)
 
void setTCPBufferEnable (bool bMode)
 
- Public Member Functions inherited from zeus::TZObject
 TZObject ()
 
 TZObject (const TString &strName)
 
 TZObject (const IString &strName)
 
Uint getHash () const
 
TString toString () const
 
virtual TString getObjName () const
 
virtual void setObjName (const TString &name)
 
virtual Retval MQUALIFIER askForInterface (const InterfaceID &rInterfaceID, IZUnknown *&rpIface)
 
virtual void MQUALIFIER addRef () const
 
virtual void MQUALIFIER release () const
 

Protected Member Functions

 TAbstractSocket ()
 
virtual ~TAbstractSocket ()
 
virtual void openSocket ()=0
 
- Protected Member Functions inherited from zeus::TZObject
virtual ~TZObject ()
 
 TZObject (const TZObject &rObject)
 
TZObjectoperator= (const TZObject &rObject)
 
Int getRefCounter () const
 

Static Protected Member Functions

static Retval getErrorCode (bool bHandleBlockedAsError)
 
static bool getBoolSocketOption (Int iFD, Int iOption, Int iLevel)
 
static Int getIntSocketOption (Int iFD, Int iOption, Int iLevel)
 
static void setBoolSocketOption (Int iFD, Int iOption, Int iLevel, bool bValue)
 
static void setIntSocketOption (Int iFD, Int iOption, Int iLevel, Int iValue)
 

Protected Attributes

TIPAddressm_pAddress
 Address object. More...
 
bool m_bConnected
 Connected flag. More...
 
bool m_bBlockable
 blockable flag More...
 
bool m_bReUsable
 reusable flag More...
 
Int m_iSocketFD
 File descriptor for socket. More...
 
TCriticalSectionm_rSocketLock
 Critical section to protect socket file descriptor. More...
 
- Protected Attributes inherited from zeus::TZObject
Uint m_uiID
 

Detailed Description

This class implements an abstract socket. It defines the correct handling of addresses, socket file descriptors, setting and getting socket options. Note that creating the correct file descriptor must be implemented in the sub classes.

Constructor & Destructor Documentation

§ TAbstractSocket() [1/4]

TAbstractSocket::TAbstractSocket ( TIPAddress rAddress)

Creates an abstract socket

Parameters
rAddress: address

§ TAbstractSocket() [2/4]

TAbstractSocket::TAbstractSocket ( const TString rstrAddr,
Uint  uiPort 
)

Creates an abstract socket

Parameters
rstrAddr: address or host name of the server
uiPort: Listening port

§ TAbstractSocket() [3/4]

TAbstractSocket::TAbstractSocket ( Int  iFD,
struct sockaddr_in &  rAddress 
)

Creates a Socket out of a file descriptor

Parameters
iFD: file descriptor.
rAddress: address object

§ TAbstractSocket() [4/4]

TAbstractSocket::TAbstractSocket ( )
protected

Creates an abstract socket.

§ ~TAbstractSocket()

TAbstractSocket::~TAbstractSocket ( )
protectedvirtual

Destroys the Socket. On windows platforms this will clean up the win sockets API, if the last socket is destroyed.

Member Function Documentation

§ connect()

virtual Retval zeus::TAbstractSocket::connect ( )
pure virtual

§ disconnect()

Retval TAbstractSocket::disconnect ( )
virtual

Disconnects the sockets. This will shutdown the connection first and then close the socket.

Returns
RET_NOERROR is always returned
Note
This method can be called from other threads

§ getAddress()

TString TAbstractSocket::getAddress ( ) const

Returns the address of a socket

Note
This method can be called from other threads

§ getBoolSocketOption()

bool TAbstractSocket::getBoolSocketOption ( Int  iFD,
Int  iOption,
Int  iLevel 
)
staticprotected

Returns a socket option as boolean

Parameters
iFD: Socket Descripitor
iOption: Option to check
iLevel: level
Return values
true: Option set
falseOption not set

§ getErrorCode()

Retval TAbstractSocket::getErrorCode ( bool  bHandleBlockedAsError)
staticprotected

Checks the error code of the socket and translates it to the Zeus-Error codes

Return values
RET_NOERROR: datagram received
RET_REQUEST_FAILED: Data socket not connected
RET_INVALID_DATA: Invalid connection data
RET_INVALID_TYPE: Addresses in the specified family cannot be used with this socket.
RET_INVALID_PARAMETERSome of the flags are not supported or invalid
RET_NETWORK_ERRORHost unreachable or connection dropped
RET_OUTOFMEMORY: the message is larger than the maximum supported by the underlying transport
RET_INTERNAL_ERRORInternal error caused of wrong usage of sockets
RET_ABORT: The blocking call has been interrupted
RET_ACCESS_DENIED: Access to the connection denied

§ getHostName()

TString TAbstractSocket::getHostName ( ) const

Returns the hostname of a socket

Note
This method can be called from other threads

§ getIntSocketOption()

Int TAbstractSocket::getIntSocketOption ( Int  iFD,
Int  iOption,
Int  iLevel 
)
staticprotected

Returns a socket option as integer

Parameters
iFD: Socket Descripitor
iOption: Option to check
iLevel: level
Returns
Option value

§ getPort()

Uint TAbstractSocket::getPort ( ) const

Returns the port of the socket

Note
This method can be called from other threads

§ getReceiveBufferSize()

Int zeus::TAbstractSocket::getReceiveBufferSize ( ) const
inline

Returns the buffer size of the receive buffer

Returns
buffer size

§ getSendBufferSize()

Int zeus::TAbstractSocket::getSendBufferSize ( ) const
inline

Returns the buffer size of the send buffer

Returns
buffer size

§ getSocketDescripitor()

Int zeus::TAbstractSocket::getSocketDescripitor ( ) const
inline

Returns the socket file descripitor

§ isBlockable()

bool zeus::TAbstractSocket::isBlockable ( ) const
inline

Checks if the socket is blockable

Return values
true: Socket is blockable
false: socket is non-blockable

§ isConnected()

bool TAbstractSocket::isConnected ( ) const

Returns the socket status

Return values
true: Socket is connected
false: socket is disconnected
Note
This method can be called from other threads

§ isReUsable()

bool zeus::TAbstractSocket::isReUsable ( ) const
inline

Checks if the socket binding is reusable.

Return values
true: Socket address is reusable
false: socket address is not reusable

§ isValid()

bool TAbstractSocket::isValid ( ) const

Checks if the socket is valid

Note
This method can be called from other threads

§ openSocket()

virtual void zeus::TAbstractSocket::openSocket ( )
protectedpure virtual

§ setBlockable()

void TAbstractSocket::setBlockable ( bool  bMode)

sets or removes the blockable mode of a socket

Note
This method can be called from other threads

§ setBoolSocketOption()

void TAbstractSocket::setBoolSocketOption ( Int  iFD,
Int  iOption,
Int  iLevel,
bool  bValue 
)
staticprotected

Returns a socket option as boolean

Parameters
iFD: Socket Descripitor
iOption: Option to check
iLevel: level
bValue: Option value

§ setIntSocketOption()

void TAbstractSocket::setIntSocketOption ( Int  iFD,
Int  iOption,
Int  iLevel,
Int  iValue 
)
staticprotected

Returns a socket option as integer

Parameters
iFD: Socket Descripitor
iOption: Option to check
iLevel: level
iValue: Option value

§ setReceiveBufferSize()

void zeus::TAbstractSocket::setReceiveBufferSize ( Int  iSize)
inline

sets the receive buffer size

Parameters
iSize: buffer size

§ setReUsable()

void zeus::TAbstractSocket::setReUsable ( bool  bMode)
inline

Call this method to reuse the server connection even if the previous server connection is still waiting for closing. This will avoid problems reconnection to the address:port.

Parameters
bMode: mode flag

§ setSendBufferSize()

void zeus::TAbstractSocket::setSendBufferSize ( Int  iSize)
inline

sets the sends buffer size

Parameters
iSize: buffer size

§ setTCPBufferEnable()

void zeus::TAbstractSocket::setTCPBufferEnable ( bool  bMode)
inline

enables or disables the TCP buffer. By default the buffer is enabled. Incase to send the data immediately, the Nagle algorithm must be disabled (=false) by using TCP_NODELAY option

Member Data Documentation

§ m_bBlockable

bool zeus::TAbstractSocket::m_bBlockable
protected

blockable flag

§ m_bConnected

bool zeus::TAbstractSocket::m_bConnected
protected

Connected flag.

§ m_bReUsable

bool zeus::TAbstractSocket::m_bReUsable
protected

reusable flag

§ m_iSocketFD

Int zeus::TAbstractSocket::m_iSocketFD
protected

File descriptor for socket.

§ m_pAddress

TIPAddress* zeus::TAbstractSocket::m_pAddress
protected

Address object.

§ m_rSocketLock

TCriticalSection& zeus::TAbstractSocket::m_rSocketLock
protected

Critical section to protect socket file descriptor.


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


Written by Benjamin Hadorn http://www.xatlantis.ch.
Last change made on Tue Sep 13 2016 22:31:48