# OpalTransport Class Reference

`#include <transports.h>`

Inheritance diagram for OpalTransport:

[legend]
Collaboration diagram for OpalTransport:
[legend]

## Operations

typedef PNotifierTemplate< bool & > | WriteConnectCallback
enum | PromisciousModes { AcceptFromRemoteOnly, AcceptFromAnyAutoSet, AcceptFromAny, NumPromisciousModes }
virtual PBoolean | IsReliable () const =0
virtual bool | IsAuthenticated (const PString &) const
virtual PString | GetInterface () const
virtual bool | SetInterface (const PString &iface)
virtual OpalTransportAddress | GetLocalAddress (bool allowNAT=true) const =0
virtual PBoolean | SetLocalAddress (const OpalTransportAddress &address)=0
virtual OpalTransportAddress | GetRemoteAddress () const =0
virtual PBoolean | SetRemoteAddress (const OpalTransportAddress &address)=0
virtual PBoolean | Connect ()=0
PBoolean | ConnectTo (const OpalTransportAddress &address)
virtual PBoolean | Close ()
void | CloseWait ()
void | CleanUpOnTermination ()
virtual PBoolean | IsCompatibleTransport (const OpalTransportAddress &address) const =0
| Promiscious modes for transport.
virtual void | SetPromiscuous (PromisciousModes promiscuous)
virtual OpalTransportAddress | GetLastReceivedAddress () const
virtual PString | GetLastReceivedInterface () const
virtual PBoolean | ReadPDU (PBYTEArray &packet)=0
virtual PBoolean | WritePDU (const PBYTEArray &pdu)=0
virtual bool | WriteConnect (const WriteConnectCallback &function)
void | SetKeepAlive (const PTimeInterval &timeout, const PBYTEArray &data)
virtual void | AttachThread (PThread *thread)
virtual PBoolean | IsRunning () const

## Construction

| ~OpalTransport ()
| OpalTransport (OpalEndPoint &endpoint, PChannel *channel)

## Public Member Functions

OpalEndPoint & | GetEndPoint () const
virtual const PCaselessString & | GetProtoPrefix () const =0
bool | IsOpen () const
bool | IsGood () const
PChannel::Errors | GetErrorCode (PChannel::ErrorGroup group=PChannel::NumErrorGroups) const
PString | GetErrorText (PChannel::ErrorGroup group=PChannel::NumErrorGroups) const
int | GetErrorNumber (PChannel::ErrorGroup group=PChannel::NumErrorGroups) const
void | SetReadTimeout (const PTimeInterval &t)
PChannel * | GetChannel () const
void | SetChannel (PChannel *chan)
Overrides from PObject
void | PrintOn (ostream &strm) const
virtual PBoolean | Write (const void *buf, PINDEX len)

## Protected Member Functions

| PDECLARE_NOTIFIER (PTimer, OpalTransport, KeepAlive)

## Protected Attributes

OpalEndPoint & | endpoint
PChannel * | m_channel
PThread * | m_thread
| Thread handling the transport.
PTimer | m_keepAliveTimer
PBYTEArray | m_keepAliveData

## Detailed Description

This class describes a I/O transport for a protocol. A "transport" is an object that allows the transfer and processing of data from one entity to another.

## Member Typedef Documentation

typedef PNotifierTemplate<bool &> OpalTransport::WriteConnectCallback

## Member Enumeration Documentation

enum OpalTransport::PromisciousModes

Enumerator:

  AcceptFromRemoteOnly |
  AcceptFromAnyAutoSet |
  AcceptFromAny |
  NumPromisciousModes |

## Constructor & Destructor Documentation

OpalTransport::OpalTransport | ( | OpalEndPoint & | endpoint,
|  | PChannel * | channel |
| ) |  |  | `[protected]`

Create a new transport channel.

OpalTransport::~OpalTransport | ( |  | ) |

Destroy the transport channel.

## Member Function Documentation

virtual void OpalTransport::AttachThread | ( | PThread * | thread | ) | `[virtual]`

Attach a thread to the transport.

void OpalTransport::CleanUpOnTermination | ( |  | ) | `[inline]`

Close channel and wait for associated thread to terminate. For backward compatibility with OpenH323, now deprecated.

virtual PBoolean OpalTransport::Close | ( |  | ) | `[virtual]`

Close the channel.

void OpalTransport::CloseWait | ( |  | ) |

Close channel and wait for associated thread to terminate.

virtual PBoolean OpalTransport::Connect | ( |  | ) | `[pure virtual]`

Connect to the remote address.

Implemented in OpalTransportTCP, and OpalTransportUDP.

PBoolean OpalTransport::ConnectTo | ( | const OpalTransportAddress & | address | ) | `[inline]`

Connect to the specified address.

PChannel* OpalTransport::GetChannel | ( |  | ) | const`[inline]`

OpalEndPoint& OpalTransport::GetEndPoint | ( |  | ) | const`[inline]`

PChannel::Errors OpalTransport::GetErrorCode | ( | PChannel::ErrorGroup | group = `PChannel::NumErrorGroups` | ) | const`[inline]`

int OpalTransport::GetErrorNumber | ( | PChannel::ErrorGroup | group = `PChannel::NumErrorGroups` | ) | const`[inline]`

PString OpalTransport::GetErrorText | ( | PChannel::ErrorGroup | group = `PChannel::NumErrorGroups` | ) | const`[inline]`

virtual PString OpalTransport::GetInterface | ( |  | ) | const`[virtual]`

Get the interface this transport is bound to. This is generally only relevant for datagram based transports such as UDP and TCP is always bound to a local interface once open.

The default behaviour returns the local address via GetLocalAddress()

Reimplemented in OpalTransportUDP.

virtual OpalTransportAddress OpalTransport::GetLastReceivedAddress | ( |  | ) | const`[virtual]`

Get the transport address of the last received PDU.

Default behaviour returns GetRemoteAddress().

Reimplemented in OpalTransportUDP.

virtual PString OpalTransport::GetLastReceivedInterface | ( |  | ) | const`[virtual]`

Get the interface of the last received PDU arrived on.

Default behaviour returns GetLocalAddress().

Reimplemented in OpalTransportUDP.

virtual OpalTransportAddress OpalTransport::GetLocalAddress | ( | bool | allowNAT = `true` | ) | const`[pure virtual]`

Get the transport dependent name of the local endpoint.

Parameters:

  allowNAT | Allow translation if remote needs NAT

Implemented in OpalTransportIP, and OpalTransportUDP.

virtual const PCaselessString& OpalTransport::GetProtoPrefix | ( |  | ) | const`[pure virtual]`

Get the prefix for this transports protocol type.

Implemented in OpalTransportIP, OpalTransportTCP, and OpalTransportUDP.

virtual OpalTransportAddress OpalTransport::GetRemoteAddress | ( |  | ) | const`[pure virtual]`

Get the transport address of the remote endpoint.

Implemented in OpalTransportIP.

virtual bool OpalTransport::IsAuthenticated | ( | const PString & |  | ) | const`[inline, virtual]`

Get indication of the remote being authenticated. Note, non TLS always return true.

virtual PBoolean OpalTransport::IsCompatibleTransport | ( | const OpalTransportAddress & | address | ) | const`[pure virtual]`

Promiscious modes for transport.

Check that the transport address is compatible with transport.

Implemented in OpalTransportTCP, and OpalTransportUDP.

bool OpalTransport::IsGood | ( |  | ) | const`[inline]`

bool OpalTransport::IsOpen | ( |  | ) | const`[inline]`

virtual PBoolean OpalTransport::IsReliable | ( |  | ) | const`[pure virtual]`

Get indication of the type of underlying transport.

Implemented in OpalTransportTCP, and OpalTransportUDP.

virtual PBoolean OpalTransport::IsRunning | ( |  | ) | const`[virtual]`

Determine of the transport is running with a background thread.

OpalTransport::PDECLARE_NOTIFIER | ( | PTimer | ,
|  | OpalTransport | ,
|  | KeepAlive |  |
| ) |  |  | `[protected]`

void OpalTransport::PrintOn | ( | ostream & | strm | ) | const

Print the description of the listener to the stream.

virtual PBoolean OpalTransport::ReadPDU | ( | PBYTEArray & | packet | ) | `[pure virtual]`

Read a protocol data unit from the transport. This will read using the transports mechanism for PDU boundaries, for example UDP is a single Read() call, while for TCP there is a TPKT header that indicates the size of the PDU.

If false is returned but there is data returned in the `packet` that indicates that the available buffer space was too small, e.g. an EMSGSIZE error was returned by recvfrom.

Parameters:

  packet | Packet read from transport

Implemented in OpalTransportTCP, and OpalTransportUDP.

void OpalTransport::SetChannel | ( | PChannel * | chan | ) | `[inline]`

virtual bool OpalTransport::SetInterface | ( | const PString & | iface | ) | `[virtual]`

Bind this transport to an interface. This is generally only relevant for datagram based transports such as UDP and TCP is always bound to a local interface once open.

The default behaviour does nothing.

Parameters:

  iface | Interface to use

Reimplemented in OpalTransportUDP.

void OpalTransport::SetKeepAlive | ( | const PTimeInterval & | timeout,
|  | const PBYTEArray & | data |
| ) |  |  |

Set keep alive time and data. The data is sent on the transport if no traffic has occurred for the specified time.

virtual PBoolean OpalTransport::SetLocalAddress | ( | const OpalTransportAddress & | address | ) | `[pure virtual]`

Set local address to connect from. Note that this may not work for all transport types or may work only before Connect() has been called.

Implemented in OpalTransportIP, and OpalTransportUDP.

virtual void OpalTransport::SetPromiscuous | ( | PromisciousModes | promiscuous | ) | `[virtual]`

Set read to promiscuous mode. Normally only reads from the specifed remote address are accepted. This flag allows packets to be accepted from any remote, provided the underlying protocol can do so. For example TCP will do nothing.

The Read() call may optionally set the remote address automatically to whatever the sender host of the last received message was.

Default behaviour does nothing.

void OpalTransport::SetReadTimeout | ( | const PTimeInterval & | t | ) | `[inline]`

virtual PBoolean OpalTransport::SetRemoteAddress | ( | const OpalTransportAddress & | address | ) | `[pure virtual]`

Set remote address to connect to. Note that this does not necessarily initiate a transport level connection, but only indicates where to connect to. The actual connection is made by the Connect() function.

Implemented in OpalTransportIP, and OpalTransportUDP.

virtual PBoolean OpalTransport::Write | ( | const void * | buf,
|  | PINDEX | len |
| ) |  |  | `[virtual]`

Low level write to the channel. This function will block until the requested number of characters are written or the write timeout is reached. The GetLastWriteCount() function returns the actual number of bytes written.

This will use the `writeChannel` pointer to actually do the write. If `writeChannel` is null the this asserts.

The GetErrorCode() function should be consulted after Write() returns false to determine what caused the failure.

Returns:
  true if at least len bytes were written to the channel.

Parameters:

  buf | Pointer to a block of memory to write.
  len | Number of bytes to write.

virtual bool OpalTransport::WriteConnect | ( | const WriteConnectCallback & | function | ) | `[virtual]`

Write the first packet to the transport, after a connect. This will adjust the transport object and call the callback function, possibly multiple times for some transport types.

It is expected that this is used just after a Connect() call where some transports (eg UDP) cannot determine its local address which is required in the PDU to be sent. This must be done fer each interface so WriteConnect() calls WriteConnectCallback for each interface. The subsequent ReadPDU() returns the answer from the first interface.

The default behaviour simply calls the WriteConnectCallback function.

Parameters:

  function | Function for writing data

virtual PBoolean OpalTransport::WritePDU | ( | const PBYTEArray & | pdu | ) | `[pure virtual]`

Write a packet to the transport. This will write using the transports mechanism for PDU boundaries, for example UDP is a single Write() call, while for TCP there is a TPKT header that indicates the size of the PDU.

Parameters:

  pdu | Packet to write

Implemented in OpalTransportTCP, and OpalTransportUDP.

## Field Documentation

OpalEndPoint& OpalTransport::endpoint `[protected]`

PChannel* OpalTransport::m_channel `[protected]`

PBYTEArray OpalTransport::m_keepAliveData `[protected]`

PTimer OpalTransport::m_keepAliveTimer `[protected]`

PThread* OpalTransport::m_thread `[protected]`

Thread handling the transport.

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

- transports.h