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)
 
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)
 
int maxPendingConnections (void)
 
void setMaxPendingConnections (int n)
 
quint16 serverPort (void)
 
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 (qt_socket_fd_t socket)
 

Static Private Member Functions

static void SelectDefaultListen (bool force=false)
 

Private Attributes

bool m_listening
 
int m_maxPendingConn
 
quint16 m_port
 
QNetworkProxy m_proxy
 
QList< PrivTcpServer * > m_tcpServers
 
QList< PrivUdpSocket * > m_udpSockets
 
PrivUdpSocketm_lastUdpSocket
 

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.

Definition at line 59 of file serverpool.h.

Constructor & Destructor Documentation

◆ ServerPool()

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

Definition at line 67 of file serverpool.cpp.

◆ ~ServerPool()

ServerPool::~ServerPool ( void  )

Definition at line 73 of file serverpool.cpp.

Member Function Documentation

◆ RefreshDefaultListen()

void ServerPool::RefreshDefaultListen ( void  )
static

Definition at line 286 of file serverpool.cpp.

◆ DefaultListen()

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

◆ DefaultListenIPv4()

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

Definition at line 303 of file serverpool.cpp.

Referenced by DefaultListen().

◆ DefaultListenIPv6()

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

Definition at line 317 of file serverpool.cpp.

Referenced by DefaultListen().

◆ DefaultBroadcast()

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

Definition at line 331 of file serverpool.cpp.

Referenced by MythUDPListener::Enable().

◆ DefaultBroadcastIPv4()

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

Definition at line 342 of file serverpool.cpp.

Referenced by DefaultBroadcast().

◆ DefaultBroadcastIPv6()

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

Definition at line 357 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 472 of file serverpool.cpp.

◆ listen() [3/3]

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

Definition at line 482 of file serverpool.cpp.

◆ bind() [1/3]

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

Definition at line 488 of file serverpool.cpp.

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

◆ bind() [2/3]

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

Definition at line 578 of file serverpool.cpp.

◆ bind() [3/3]

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

Definition at line 587 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 629 of file serverpool.cpp.

◆ isListening()

bool ServerPool::isListening ( void  )
inline

Definition at line 91 of file serverpool.h.

Referenced by MediaServer::Init().

◆ maxPendingConnections()

int ServerPool::maxPendingConnections ( void  )
inline

Definition at line 92 of file serverpool.h.

◆ setMaxPendingConnections()

void ServerPool::setMaxPendingConnections ( int  n)
inline

Definition at line 93 of file serverpool.h.

Referenced by HttpServer::HttpServer(), and WebSocketServer::WebSocketServer().

◆ serverPort()

quint16 ServerPool::serverPort ( void  )
inline

Definition at line 94 of file serverpool.h.

◆ proxy()

QNetworkProxy ServerPool::proxy ( void  )
inline

Definition at line 96 of file serverpool.h.

◆ setProxy()

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

◆ 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 685 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 718 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 754 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 820 of file serverpool.cpp.

◆ newConnection

void ServerPool::newConnection ( QTcpSocket *  )
signal

Referenced by newTcpConnection().

◆ newDatagram

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

Referenced by newUdpDatagram().

◆ newUdpDatagram

void ServerPool::newUdpDatagram ( void  )
protectedvirtualslot

Definition at line 653 of file serverpool.cpp.

Referenced by bind().

◆ newTcpConnection

void ServerPool::newTcpConnection ( qt_socket_fd_t  socket)
protectedvirtualslot

Reimplemented in MythServer.

Definition at line 635 of file serverpool.cpp.

Referenced by listen().

◆ SelectDefaultListen()

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

Member Data Documentation

◆ m_listening

bool ServerPool::m_listening
private

Definition at line 120 of file serverpool.h.

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

◆ m_maxPendingConn

int ServerPool::m_maxPendingConn
private

Definition at line 121 of file serverpool.h.

Referenced by listen().

◆ m_port

quint16 ServerPool::m_port
private

Definition at line 122 of file serverpool.h.

Referenced by bind(), and listen().

◆ m_proxy

QNetworkProxy ServerPool::m_proxy
private

Definition at line 123 of file serverpool.h.

Referenced by listen().

◆ m_tcpServers

QList<PrivTcpServer*> ServerPool::m_tcpServers
private

Definition at line 125 of file serverpool.h.

Referenced by close(), and listen().

◆ m_udpSockets

QList<PrivUdpSocket*> ServerPool::m_udpSockets
private

Definition at line 126 of file serverpool.h.

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

◆ m_lastUdpSocket

PrivUdpSocket* ServerPool::m_lastUdpSocket
private

Definition at line 127 of file serverpool.h.

Referenced by close(), and writeDatagram().


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