PMonitoredSockets Class Reference

#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
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
virtual PChannel::Errors ReadFromBundle (void *buffer, PINDEX length, PIPSocket::Address &addr, WORD &port, PString &iface, PINDEX &lastReadCount, const PTimeInterval &timeout)=0
void SetSTUN (PSTUNClient *stunClient)
 Set the STUN server.
PSTUNClientGetSTUN () const

Static Public Member Functions

static PMonitoredSocketsCreate (const PString &iface, PBoolean reuseAddr=PFalse, PSTUNClient *stunClient=NULL)

Protected Member Functions

 PMonitoredSockets (PBoolean reuseAddr, PSTUNClient *stunClient)
virtual void OnRemoveSTUNClient (const PSTUNClient *stun)
 Called when a PSTUNClient is about to be destroyed.
PBoolean CreateSocket (SocketInfo &info, const PIPSocket::Address &binding)
PBoolean DestroySocket (SocketInfo &info)
PBoolean GetSocketAddress (const SocketInfo &info, PIPSocket::Address &address, WORD &port, PBoolean 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)

Protected Attributes

WORD localPort
PBoolean reuseAddress
PSTUNClientstun
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 ( PBoolean  reuseAddr,
PSTUNClient stunClient 
) [protected]


Member Function Documentation

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 PTrue if all sockets are opened.

Implemented in PMonitoredSocketBundle, and PSingleMonitoredSocket.

PBoolean PMonitoredSockets::IsOpen (  )  const [inline]

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

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

Close all socket(s).

Implemented in PMonitoredSocketBundle, and PSingleMonitoredSocket.

WORD PMonitoredSockets::GetPort (  )  const [inline]

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

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:
address  Interface to get address for
port  Address of interface
usingNAT  Port listening on Require NAT address/port

Implemented in PMonitoredSocketBundle, and PSingleMonitoredSocket.

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:
length  Data to write
addr  Length of data
port  Remote IP address to write to
iface  Remote port to write to
lastWriteCount  Interface to use for writing

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:
length  Data to read
addr  Maximum length of data
port  Remote IP address data came from
iface  Remote port data came from
lastReadCount  Interface to use for read, also one data was read on
timeout  Actual length of data read Time to wait for data

Implemented in PMonitoredSocketBundle, and PSingleMonitoredSocket.

void PMonitoredSockets::SetSTUN ( PSTUNClient stunClient  )  [inline]

Set the STUN server.

PSTUNClient* PMonitoredSockets::GetSTUN (  )  const [inline]

static PMonitoredSockets* PMonitoredSockets::Create ( const PString iface,
PBoolean  reuseAddr = PFalse,
PSTUNClient stunClient = 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:
reuseAddr  Interface name to create socket for
stunClient  Re-use or exclusive port number STUN client code

virtual void PMonitoredSockets::OnRemoveSTUNClient ( const PSTUNClient stun  )  [protected, virtual]

Called when a PSTUNClient is about to be destroyed.

Reimplemented from PInterfaceMonitorClient.

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

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

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

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

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


Member Data Documentation

WORD PMonitoredSockets::localPort [protected]

PBoolean PMonitoredSockets::reuseAddress [protected]

PSTUNClient* PMonitoredSockets::stun [protected]

bool PMonitoredSockets::opened [protected]

PUDPSocket PMonitoredSockets::interfaceAddedSignal [protected]


The documentation for this class was generated from the following file:
Generated on Mon Dec 10 11:19:00 2007 for PTLib by  doxygen 1.5.1