MythTV  master
Signals | Public Member Functions | Static Public Member Functions | Protected Slots | Static Private Member Functions | Private Attributes | List of all members
ServerPool Class Reference

Manages a collection of sockets listening on different ports. More...

#include <serverpool.h>

Inheritance diagram for ServerPool:
Inheritance graph
[legend]
Collaboration diagram for ServerPool:
Collaboration graph
[legend]

Signals

void newConnection (QTcpSocket *)
 
void newDatagram (QByteArray, QHostAddress, quint16)
 

Public Member Functions

 ServerPool (QObject *parent=nullptr)
 
 ~ServerPool (void) override
 
bool listen (QList< QHostAddress > addrs, quint16 port, bool requireall=true, PoolServerType type=kTCPServer)
 
bool listen (QStringList addrs, quint16 port, bool requireall=true, PoolServerType type=kTCPServer)
 
bool listen (quint16 port, bool requireall=true, PoolServerType type=kTCPServer)
 
bool bind (QList< QHostAddress > addrs, quint16 port, bool requireall=true)
 
bool bind (QStringList addrs, quint16 port, bool requireall=true)
 
bool bind (quint16 port, bool requireall=true)
 
qint64 writeDatagram (const char *data, qint64 size, const QHostAddress &addr, quint16 port)
 
qint64 writeDatagram (const QByteArray &datagram, const QHostAddress &addr, quint16 port)
 
bool isListening (void) const
 
int maxPendingConnections (void) const
 
void setMaxPendingConnections (int n)
 
quint16 serverPort (void) const
 
QNetworkProxy proxy (void)
 
void setProxy (const QNetworkProxy &proxy)
 
void close (void)
 
int tryListeningPort (int baseport, int range=1)
 tryListeningPort More...
 
int tryBindingPort (int baseport, int range=1)
 tryBindingPort More...
 

Static Public Member Functions

static void RefreshDefaultListen (void)
 
static QList< QHostAddress > DefaultListen (void)
 
static QList< QHostAddress > DefaultListenIPv4 (void)
 
static QList< QHostAddress > DefaultListenIPv6 (void)
 
static QList< QHostAddress > DefaultBroadcast (void)
 
static QList< QHostAddress > DefaultBroadcastIPv4 (void)
 
static QList< QHostAddress > DefaultBroadcastIPv6 (void)
 
static int tryListeningPort (QTcpServer *server, int baseport, int range=1, bool *isipv6=nullptr)
 tryListeningPort More...
 
static int tryBindingPort (QUdpSocket *socket, int baseport, int range=1, bool *isipv6=nullptr)
 tryBindingPort More...
 

Protected Slots

virtual void newUdpDatagram (void)
 
virtual void newTcpConnection (qintptr socket)
 

Static Private Member Functions

static void SelectDefaultListen (bool force=false)
 

Private Attributes

bool m_listening {false}
 
int m_maxPendingConn {30}
 
quint16 m_port {0}
 
QNetworkProxy m_proxy {QNetworkProxy::NoProxy}
 
QList< PrivTcpServer * > m_tcpServers
 
QList< PrivUdpSocket * > m_udpSockets
 
PrivUdpSocketm_lastUdpSocket {nullptr}
 

Detailed Description

Manages a collection of sockets listening on different ports.

This class allows a TCP or UDP server to listen on a list of addresses rather than limited to a single or all addresses. This is done by opening a separate server for each defined QHostAddress, and signalling collectively for any new connections.

This can be subclassed with new 'newTcpConnection()' and 'newConnection()' methods to allow signalling for alternate socket types. For a minimal example see MythServer.

Definition at line 59 of file serverpool.h.

Constructor & Destructor Documentation

◆ ServerPool()

ServerPool::ServerPool ( QObject *  parent = nullptr)
inlineexplicit

Definition at line 64 of file serverpool.h.

◆ ~ServerPool()

ServerPool::~ServerPool ( void  )
override

Definition at line 70 of file serverpool.cpp.

Member Function Documentation

◆ RefreshDefaultListen()

void ServerPool::RefreshDefaultListen ( void  )
static

Definition at line 292 of file serverpool.cpp.

◆ DefaultListen()

QList< QHostAddress > ServerPool::DefaultListen ( void  )
static

◆ DefaultListenIPv4()

QList< QHostAddress > ServerPool::DefaultListenIPv4 ( void  )
static

Definition at line 309 of file serverpool.cpp.

Referenced by DefaultListen().

◆ DefaultListenIPv6()

QList< QHostAddress > ServerPool::DefaultListenIPv6 ( void  )
static

Definition at line 322 of file serverpool.cpp.

Referenced by DefaultListen().

◆ DefaultBroadcast()

QList< QHostAddress > ServerPool::DefaultBroadcast ( void  )
static

Definition at line 335 of file serverpool.cpp.

Referenced by MythUDPListener::DoEnable().

◆ DefaultBroadcastIPv4()

QList< QHostAddress > ServerPool::DefaultBroadcastIPv4 ( void  )
static

Definition at line 346 of file serverpool.cpp.

Referenced by DefaultBroadcast().

◆ DefaultBroadcastIPv6()

QList< QHostAddress > ServerPool::DefaultBroadcastIPv6 ( void  )
static

Definition at line 362 of file serverpool.cpp.

Referenced by DefaultBroadcast().

◆ listen() [1/3]

bool ServerPool::listen ( QList< QHostAddress >  addrs,
quint16  port,
bool  requireall = true,
PoolServerType  type = kTCPServer 
)

◆ listen() [2/3]

bool ServerPool::listen ( QStringList  addrs,
quint16  port,
bool  requireall = true,
PoolServerType  type = kTCPServer 
)

Definition at line 476 of file serverpool.cpp.

◆ listen() [3/3]

bool ServerPool::listen ( quint16  port,
bool  requireall = true,
PoolServerType  type = kTCPServer 
)

Definition at line 485 of file serverpool.cpp.

◆ bind() [1/3]

bool ServerPool::bind ( QList< QHostAddress >  addrs,
quint16  port,
bool  requireall = true 
)

Definition at line 491 of file serverpool.cpp.

Referenced by bind(), MythUDPListener::DoEnable(), and tryBindingPort().

◆ bind() [2/3]

bool ServerPool::bind ( QStringList  addrs,
quint16  port,
bool  requireall = true 
)

Definition at line 598 of file serverpool.cpp.

◆ bind() [3/3]

bool ServerPool::bind ( quint16  port,
bool  requireall = true 
)

Definition at line 606 of file serverpool.cpp.

◆ writeDatagram() [1/2]

qint64 ServerPool::writeDatagram ( const char *  data,
qint64  size,
const QHostAddress &  addr,
quint16  port 
)

◆ writeDatagram() [2/2]

qint64 ServerPool::writeDatagram ( const QByteArray &  datagram,
const QHostAddress &  addr,
quint16  port 
)

Definition at line 668 of file serverpool.cpp.

◆ isListening()

bool ServerPool::isListening ( void  ) const
inline

Definition at line 92 of file serverpool.h.

Referenced by MythHTTPServer::EnableDisable(), and MediaServer::Init().

◆ maxPendingConnections()

int ServerPool::maxPendingConnections ( void  ) const
inline

Definition at line 93 of file serverpool.h.

◆ setMaxPendingConnections()

void ServerPool::setMaxPendingConnections ( int  n)
inline

◆ serverPort()

quint16 ServerPool::serverPort ( void  ) const
inline

Definition at line 95 of file serverpool.h.

Referenced by MythHTTPServer::EnableDisable().

◆ proxy()

QNetworkProxy ServerPool::proxy ( void  )
inline

Definition at line 97 of file serverpool.h.

◆ setProxy()

void ServerPool::setProxy ( const QNetworkProxy &  proxy)
inline

Definition at line 98 of file serverpool.h.

Referenced by MythSocketManager::Listen(), and MainServer::MainServer().

◆ close()

void ServerPool::close ( void  )

◆ tryListeningPort() [1/2]

int ServerPool::tryListeningPort ( int  baseport,
int  range = 1 
)

tryListeningPort

Description: Tells the server to listen for incoming connections on port port. The server will attempt to listen on all local interfaces.

Usage: baseport: port to listen on. range: range of ports to try (default 1)

Returns port used on success; otherwise returns -1.

Definition at line 724 of file serverpool.cpp.

Referenced by MythRAOPConnection::ProcessRequest(), MythRAOPDevice::Start(), and MythAirplayServer::Start().

◆ tryBindingPort() [1/2]

int ServerPool::tryBindingPort ( int  baseport,
int  range = 1 
)

tryBindingPort

Description: Binds this socket for incoming connections on port port. The socket will attempt to bind on all local interfaces.

Usage: baseport: port to bind to. range: range of ports to try (default 1)

Returns port used on success; otherwise returns -1.

Definition at line 757 of file serverpool.cpp.

Referenced by MythRAOPConnection::Init(), and MythRAOPConnection::ProcessRequest().

◆ tryListeningPort() [2/2]

int ServerPool::tryListeningPort ( QTcpServer *  server,
int  baseport,
int  range = 1,
bool isipv6 = nullptr 
)
static

tryListeningPort

Description: Tells the server to listen for incoming connections on port port. The server will attempt to listen on all IPv6 and IPv4 interfaces. If IPv6 isn't available, the server will listen on all IPv4 network interfaces.

Usage: server: QTcpServer object to use baseport: port to listen on. If port is 0, a port is chosen automatically. range: range of ports to try (default 1) isipv6: is set to true if IPv6 was successful (default nullptr)

Returns port used on success; otherwise returns -1.

Definition at line 793 of file serverpool.cpp.

◆ tryBindingPort() [2/2]

int ServerPool::tryBindingPort ( QUdpSocket *  socket,
int  baseport,
int  range = 1,
bool isipv6 = nullptr 
)
static

tryBindingPort

Description: Binds this socket for incoming connections on port port. The socket will attempt to bind on all IPv6 and IPv4 interfaces. If IPv6 isn't available, the socket will be bound to all IPv4 network interfaces.

Usage: socket: QUdpSocket object to use baseport: port to bind to. range: range of ports to try (default 1) isipv6: is set to true if IPv6 was successful (default nullptr)

Returns port used on success; otherwise returns -1.

Definition at line 857 of file serverpool.cpp.

◆ newConnection

void ServerPool::newConnection ( QTcpSocket *  )
signal

◆ newDatagram

void ServerPool::newDatagram ( QByteArray  ,
QHostAddress  ,
quint16   
)
signal

◆ newUdpDatagram

void ServerPool::newUdpDatagram ( void  )
protectedvirtualslot

Definition at line 692 of file serverpool.cpp.

Referenced by bind().

◆ newTcpConnection

void ServerPool::newTcpConnection ( qintptr  socket)
protectedvirtualslot

Definition at line 674 of file serverpool.cpp.

Referenced by listen().

◆ SelectDefaultListen()

void ServerPool::SelectDefaultListen ( bool  force = false)
staticprivate

Member Data Documentation

◆ m_listening

bool ServerPool::m_listening {false}
private

Definition at line 121 of file serverpool.h.

Referenced by bind(), close(), listen(), and writeDatagram().

◆ m_maxPendingConn

int ServerPool::m_maxPendingConn {30}
private

Definition at line 122 of file serverpool.h.

Referenced by listen().

◆ m_port

quint16 ServerPool::m_port {0}
private

Definition at line 123 of file serverpool.h.

Referenced by bind(), and listen().

◆ m_proxy

QNetworkProxy ServerPool::m_proxy {QNetworkProxy::NoProxy}
private

Definition at line 124 of file serverpool.h.

Referenced by listen().

◆ m_tcpServers

QList<PrivTcpServer*> ServerPool::m_tcpServers
private

Definition at line 126 of file serverpool.h.

Referenced by close(), and listen().

◆ m_udpSockets

QList<PrivUdpSocket*> ServerPool::m_udpSockets
private

Definition at line 127 of file serverpool.h.

Referenced by bind(), close(), and writeDatagram().

◆ m_lastUdpSocket

PrivUdpSocket* ServerPool::m_lastUdpSocket {nullptr}
private

Definition at line 128 of file serverpool.h.

Referenced by close(), and writeDatagram().


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