PMonitoredSockets Class Reference

This is a base class for UDP socket(s) that are monitored for interface changes. More...

#include <psockbun.h>

Inheritance diagram for PMonitoredSockets:

PInterfaceMonitorClient PSafeObject PObject PMonitoredSocketBundle PSingleMonitoredSocket List of all members.

Public Member Functions

virtual PBoolean Open (WORD port)=0
 Open the socket(s) using the specified port.
PBoolean IsOpen () const
 Indicate if the socket(s) are open and ready for reads/writes.
virtual PBoolean Close ()=0
 Close all socket(s).
WORD GetPort () const
 Return the local port number being used by the socket(s).
virtual PBoolean GetAddress (const PString &iface, PIPSocket::Address &address, WORD &port, PBoolean usingNAT) const =0
 Get the local address for the given interface.
virtual PChannel::Errors WriteToBundle (const void *buffer, PINDEX length, const PIPSocket::Address &addr, WORD port, const PString &iface, PINDEX &lastWriteCount)=0
 Write to the remote address/port using the socket(s) available.
virtual PChannel::Errors ReadFromBundle (void *buffer, PINDEX length, PIPSocket::Address &addr, WORD &port, PString &iface, PINDEX &lastReadCount, const PTimeInterval &timeout)=0
 Read fram a remote address/port using the socket(s) available.
void SetNatMethod (PNatMethod *method)
 Set the NAT method, eg STUN client pointer.
PNatMethodGetNatMethod () const

Static Public Member Functions

static PMonitoredSocketsCreate (const PString &iface, bool reuseAddr=false, PNatMethod *natMethod=NULL)
 Create a new monitored socket instance based on the interface descriptor.

Protected Member Functions

 PMonitoredSockets (bool reuseAddr, PNatMethod *natMethod)
virtual void OnRemoveNatMethod (const PNatMethod *natMethod)
 Called when a NAT method is about to be destroyed.
bool CreateSocket (SocketInfo &info, const PIPSocket::Address &binding)
bool DestroySocket (SocketInfo &info)
bool GetSocketAddress (const SocketInfo &info, PIPSocket::Address &address, WORD &port, bool usingNAT) const
PChannel::Errors WriteToSocket (const void *buf, PINDEX len, const PIPSocket::Address &addr, WORD port, const SocketInfo &info, PINDEX &lastWriteCount)
PChannel::Errors ReadFromSocket (SocketInfo &info, void *buf, PINDEX len, PIPSocket::Address &addr, WORD &port, PINDEX &lastReadCount, const PTimeInterval &timeout)
PChannel::Errors ReadFromSocket (PSocket::SelectList &readers, PUDPSocket *&socket, void *buf, PINDEX len, PIPSocket::Address &addr, WORD &port, PINDEX &lastReadCount, const PTimeInterval &timeout)

Protected Attributes

WORD localPort
bool reuseAddress
PNatMethodnatMethod
bool opened
PUDPSocket interfaceAddedSignal

Classes

struct  SocketInfo

Detailed Description

This is a base class for UDP socket(s) that are monitored for interface changes.

Two derived classes are available, one that is permanently bound to an IP address and/or interface name. The second will dynamically open/close ports as interfaces are added and removed from the system.


Constructor & Destructor Documentation

PMonitoredSockets::PMonitoredSockets ( bool  reuseAddr,
PNatMethod natMethod 
) [protected]


Member Function Documentation

virtual PBoolean PMonitoredSockets::Close (  )  [pure virtual]

Close all socket(s).

Implemented in PMonitoredSocketBundle, and PSingleMonitoredSocket.

static PMonitoredSockets* PMonitoredSockets::Create ( const PString iface,
bool  reuseAddr = false,
PNatMethod natMethod = NULL 
) [static]

Create a new monitored socket instance based on the interface descriptor.

This will create a multiple or single socket derived class of PMonitoredSockets depending on teh iface parameter.

Parameters:
iface  Interface name to create socket for
reuseAddr  Re-use or exclusive port number
natMethod  NAT method

bool PMonitoredSockets::CreateSocket ( SocketInfo info,
const PIPSocket::Address binding 
) [protected]

bool PMonitoredSockets::DestroySocket ( SocketInfo info  )  [protected]

virtual PBoolean PMonitoredSockets::GetAddress ( const PString iface,
PIPSocket::Address address,
WORD &  port,
PBoolean  usingNAT 
) const [pure virtual]

Get the local address for the given interface.

Parameters:
iface  Interface to get address for
address  Address of interface
port  Port listening on
usingNAT  Require NAT address/port

Implemented in PMonitoredSocketBundle, and PSingleMonitoredSocket.

PNatMethod* PMonitoredSockets::GetNatMethod (  )  const [inline]

WORD PMonitoredSockets::GetPort (  )  const [inline]

Return the local port number being used by the socket(s).

bool PMonitoredSockets::GetSocketAddress ( const SocketInfo info,
PIPSocket::Address address,
WORD &  port,
bool  usingNAT 
) const [protected]

PBoolean PMonitoredSockets::IsOpen (  )  const [inline]

Indicate if the socket(s) are open and ready for reads/writes.

virtual void PMonitoredSockets::OnRemoveNatMethod ( const PNatMethod natMethod  )  [protected, virtual]

Called when a NAT method is about to be destroyed.

Reimplemented from PInterfaceMonitorClient.

virtual PBoolean PMonitoredSockets::Open ( WORD  port  )  [pure virtual]

Open the socket(s) using the specified port.

If port is zero then a system allocated port is used. In this case and when multiple interfaces are supported, all sockets use the same dynamic port value.

Returns true if all sockets are opened.

Implemented in PMonitoredSocketBundle, and PSingleMonitoredSocket.

virtual PChannel::Errors PMonitoredSockets::ReadFromBundle ( void *  buffer,
PINDEX  length,
PIPSocket::Address addr,
WORD &  port,
PString iface,
PINDEX &  lastReadCount,
const PTimeInterval timeout 
) [pure virtual]

Read fram a remote address/port using the socket(s) available.

If the iface parameter is empty, then the first data received on any socket(s) is used, and the iface parameter is set to the name of that interface. Otherwise the iface parameter indicates the specific interface socket to read the data from.

Parameters:
buffer  Data to read
length  Maximum length of data
addr  Remote IP address data came from
port  Remote port data came from
iface  Interface to use for read, also one data was read on
lastReadCount  Actual length of data read
timeout  Time to wait for data

Implemented in PMonitoredSocketBundle, and PSingleMonitoredSocket.

PChannel::Errors PMonitoredSockets::ReadFromSocket ( PSocket::SelectList readers,
PUDPSocket *&  socket,
void *  buf,
PINDEX  len,
PIPSocket::Address addr,
WORD &  port,
PINDEX &  lastReadCount,
const PTimeInterval timeout 
) [protected]

PChannel::Errors PMonitoredSockets::ReadFromSocket ( SocketInfo info,
void *  buf,
PINDEX  len,
PIPSocket::Address addr,
WORD &  port,
PINDEX &  lastReadCount,
const PTimeInterval timeout 
) [protected]

void PMonitoredSockets::SetNatMethod ( PNatMethod method  )  [inline]

Set the NAT method, eg STUN client pointer.

virtual PChannel::Errors PMonitoredSockets::WriteToBundle ( const void *  buffer,
PINDEX  length,
const PIPSocket::Address addr,
WORD  port,
const PString iface,
PINDEX &  lastWriteCount 
) [pure virtual]

Write to the remote address/port using the socket(s) available.

If the iface parameter is empty, then the data is written to all socket(s). Otherwise the iface parameter indicates the specific interface socket to write the data to.

Parameters:
buffer  Data to write
length  Length of data
addr  Remote IP address to write to
port  Remote port to write to
iface  Interface to use for writing
lastWriteCount  Number of bytes written

Implemented in PMonitoredSocketBundle, and PSingleMonitoredSocket.

PChannel::Errors PMonitoredSockets::WriteToSocket ( const void *  buf,
PINDEX  len,
const PIPSocket::Address addr,
WORD  port,
const SocketInfo info,
PINDEX &  lastWriteCount 
) [protected]


Member Data Documentation

PUDPSocket PMonitoredSockets::interfaceAddedSignal [protected]

WORD PMonitoredSockets::localPort [protected]

PNatMethod* PMonitoredSockets::natMethod [protected]

bool PMonitoredSockets::opened [protected]

bool PMonitoredSockets::reuseAddress [protected]


The documentation for this class was generated from the following file:
Generated on Fri Feb 15 20:58:34 2013 for PTLib by  doxygen 1.4.7