PMonitoredSockets Class Referenceabstract

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

`#include <psockbun.h>`

Inheritance diagram for PMonitoredSockets:

## Classes

struct | SocketInfo

## Public Member Functions

virtual PBoolean | Open (WORD port)=0
| Open the socket(s) using the specified port. More...
PBoolean | IsOpen () const
| Indicate if the socket(s) are open and ready for reads/writes. More...
virtual PBoolean | Close ()=0
| Close all socket(s) More...
WORD | GetPort () const
| Return the local port number being used by the socket(s) More...
virtual PBoolean | GetAddress (const PString &iface, PIPSocket::Address &address, WORD &port, PBoolean usingNAT) const =0
| Get the local address for the given interface. More...
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. More...
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. More...
void | SetNatMethod (PNatMethod *method)
| Set the NAT method, eg STUN client pointer. More...
PNatMethod * | GetNatMethod () const
Public Member Functions inherited from PInterfaceMonitorClient
| PInterfaceMonitorClient (PINDEX priority=DefaultPriority)
| ~PInterfaceMonitorClient ()
virtual PStringArray | GetInterfaces (bool includeLoopBack=false, const PIPSocket::Address &destination=PIPSocket::GetDefaultIpAny())
| Get an array of all current interface descriptors, possibly including the loopback (127.0.0.1) interface. More...
virtual PBoolean | GetInterfaceInfo (const PString &iface, InterfaceEntry &info) const
| Return information about an active interface given the descriptor string. More...
PINDEX | GetPriority () const
| Returns the priority of this client. More...
Public Member Functions inherited from PSafeObject
| PSafeObject (PSafeObject *indirectLock=NULL)
| Create a thread safe object. More...
PBoolean | SafeReference ()
| Increment the reference count for object. More...
PBoolean | SafeDereference ()
| Decrement the reference count for object. More...
PBoolean | LockReadOnly () const
| Lock the object for Read Only access. More...
void | UnlockReadOnly () const
| Release the read only lock on an object. More...
PBoolean | LockReadWrite ()
| Lock the object for Read/Write access. More...
void | UnlockReadWrite ()
| Release the read/write lock on an object. More...
void | SafeRemove ()
| Set the removed flag. More...
PBoolean | SafelyCanBeDeleted () const
| Determine if the object can be safely deleted. More...
virtual bool | GarbageCollection ()
| Do any garbage collection that may be required by the object so that it may be finally deleted. More...
Public Member Functions inherited from PObject
virtual | ~PObject ()
virtual PObject * | Clone () const
| Create a copy of the class on the heap. More...
virtual PINDEX | HashFunction () const
| This function yields a hash value required by the `PDictionary` class. More...
virtual Comparison | Compare (const PObject &obj) const
| Compare the two objects and return their relative rank. More...
virtual Comparison | CompareObjectMemoryDirect (const PObject &obj) const
| Determine the byte wise comparison of two objects. More...
bool | operator== (const PObject &obj) const
| Compare the two objects. More...
bool | operator!= (const PObject &obj) const
| Compare the two objects. More...
bool | operator< (const PObject &obj) const
| Compare the two objects. More...
bool | operator> (const PObject &obj) const
| Compare the two objects. More...
bool | operator<= (const PObject &obj) const
| Compare the two objects. More...
bool | operator>= (const PObject &obj) const
| Compare the two objects. More...
virtual const char * | GetClass (unsigned ancestor=0) const
| Get the current dynamic type of the object instance. More...
PBoolean | IsClass (const char *cls) const
virtual PBoolean | InternalIsDescendant (const char *clsName) const
| Determine if the dynamic type of the current instance is a descendent of the specified class. More...
virtual void | PrintOn (ostream &strm) const
| Output the contents of the object to the stream. More...
virtual void | ReadFrom (istream &strm)
| Input the contents of the object from the stream. More...

## Static Public Member Functions

static PMonitoredSockets * | Create (const PString &iface, bool reuseAddr=false, PNatMethod *natMethod=NULL)
| Create a new monitored socket instance based on the interface descriptor. More...
Static Public Member Functions inherited from PObject
static Comparison | InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size)
| Internal function caled from CompareObjectMemoryDirect() More...
static const char * | Class ()
| Get the name of the class as a C string. More...

## Protected Member Functions

| PMonitoredSockets (bool reuseAddr, PNatMethod *natMethod)
virtual void | OnRemoveNatMethod (const PNatMethod *natMethod)
| Called when a NAT method is about to be destroyed. More...
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 Member Functions inherited from PInterfaceMonitorClient
virtual void | OnAddInterface (const InterfaceEntry &entry)=0
| Call back function for when an interface has been added to the system. More...
virtual void | OnRemoveInterface (const InterfaceEntry &entry)=0
| Call back function for when an interface has been removed from the system. More...
Protected Member Functions inherited from PObject
| PObject ()
| Constructor for PObject, made protected so cannot ever create one on its own. More...

## Protected Attributes

WORD | localPort
bool | reuseAddress
PNatMethod * | natMethod
bool | opened
PUDPSocket | interfaceAddedSignal
Protected Attributes inherited from PInterfaceMonitorClient
PINDEX | priority

## Additional Inherited Members

Public Types inherited from PInterfaceMonitorClient
enum | { DefaultPriority = 50 }
typedef PIPSocket::InterfaceEntry | InterfaceEntry
Public Types inherited from PObject
enum | Comparison { LessThan = -1, EqualTo = 0, GreaterThan = 1 }
| Result of the comparison operation performed by the `Compare()` function. More...

## 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::PMonitoredSockets | ( | bool | reuseAddr,
|  | PNatMethod * | natMethod
| ) |  |

protected

## Member Function Documentation

## Close()

virtual PBoolean PMonitoredSockets::Close | ( |  | ) |

pure virtual

Close all socket(s)

Implemented in PSingleMonitoredSocket, and PMonitoredSocketBundle.

## Create()

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

## CreateSocket()

bool PMonitoredSockets::CreateSocket | ( | SocketInfo & | info,
|  | const PIPSocket::Address & | binding
| ) |  |

protected

## DestroySocket()

bool PMonitoredSockets::DestroySocket | ( | SocketInfo & | info | ) |

protected

## GetAddress()

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 PSingleMonitoredSocket, and PMonitoredSocketBundle.

## GetNatMethod()

PNatMethod* PMonitoredSockets::GetNatMethod | ( |  | ) | const

inline

References PInterfaceMonitor::OnRemoveNatMethod().

## GetPort()

WORD PMonitoredSockets::GetPort | ( |  | ) | const

inline

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

## GetSocketAddress()

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

protected

## IsOpen()

PBoolean PMonitoredSockets::IsOpen | ( |  | ) | const

inline

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

## OnRemoveNatMethod()

virtual void PMonitoredSockets::OnRemoveNatMethod | ( | const PNatMethod * |  | ) |

protected virtual

Called when a NAT method is about to be destroyed.

Reimplemented from PInterfaceMonitorClient.

## Open()

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 PSingleMonitoredSocket, and PMonitoredSocketBundle.

## ReadFromBundle()

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 PSingleMonitoredSocket, and PMonitoredSocketBundle.

## ReadFromSocket() [1/2]

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

protected

## ReadFromSocket() [2/2]

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

protected

## SetNatMethod()

void PMonitoredSockets::SetNatMethod | ( | PNatMethod * | method | ) |

inline

Set the NAT method, eg STUN client pointer.

## WriteToBundle()

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 PSingleMonitoredSocket, and PMonitoredSocketBundle.

## WriteToSocket()

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

protected

## Member Data Documentation

## interfaceAddedSignal

PUDPSocket PMonitoredSockets::interfaceAddedSignal

protected

## localPort

WORD PMonitoredSockets::localPort

protected

## natMethod

PNatMethod* PMonitoredSockets::natMethod

protected

## opened

bool PMonitoredSockets::opened

protected

## reuseAddress

bool PMonitoredSockets::reuseAddress

protected

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

- psockbun.h