MythTV
master
|
Manages a collection of sockets listening on different ports. More...
#include <serverpool.h>
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 |
PrivUdpSocket * | m_lastUdpSocket {nullptr} |
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.
|
inlineexplicit |
Definition at line 64 of file serverpool.h.
|
override |
Definition at line 68 of file serverpool.cpp.
|
static |
Definition at line 290 of file serverpool.cpp.
|
static |
Definition at line 299 of file serverpool.cpp.
Referenced by bind(), MythHTTPServer::BuildHosts(), MythUDPListener::DoEnable(), MediaServer::Init(), UPnp::Initialize(), listen(), and MainServer::MainServer().
|
static |
Definition at line 307 of file serverpool.cpp.
Referenced by DefaultListen().
|
static |
Definition at line 320 of file serverpool.cpp.
Referenced by DefaultListen().
|
static |
Definition at line 333 of file serverpool.cpp.
Referenced by MythUDPListener::DoEnable().
|
static |
Definition at line 344 of file serverpool.cpp.
Referenced by DefaultBroadcast().
|
static |
Definition at line 360 of file serverpool.cpp.
Referenced by DefaultBroadcast().
bool ServerPool::listen | ( | QList< QHostAddress > | addrs, |
quint16 | port, | ||
bool | requireall = true , |
||
PoolServerType | type = kTCPServer |
||
) |
Definition at line 389 of file serverpool.cpp.
Referenced by MythHTTPServer::EnableDisable(), MediaServer::Init(), LCDServer::LCDServer(), MythSocketManager::Listen(), listen(), main(), MainServer::MainServer(), and tryListeningPort().
bool ServerPool::listen | ( | QStringList | addrs, |
quint16 | port, | ||
bool | requireall = true , |
||
PoolServerType | type = kTCPServer |
||
) |
Definition at line 474 of file serverpool.cpp.
bool ServerPool::listen | ( | quint16 | port, |
bool | requireall = true , |
||
PoolServerType | type = kTCPServer |
||
) |
Definition at line 483 of file serverpool.cpp.
Definition at line 489 of file serverpool.cpp.
Referenced by bind(), MythUDPListener::DoEnable(), and tryBindingPort().
Definition at line 596 of file serverpool.cpp.
Definition at line 604 of file serverpool.cpp.
qint64 ServerPool::writeDatagram | ( | const char * | data, |
qint64 | size, | ||
const QHostAddress & | addr, | ||
quint16 | port | ||
) |
Definition at line 609 of file serverpool.cpp.
Referenced by MythRAOPConnection::SendResendRequest(), MythRAOPConnection::SendTimeRequest(), and writeDatagram().
qint64 ServerPool::writeDatagram | ( | const QByteArray & | datagram, |
const QHostAddress & | addr, | ||
quint16 | port | ||
) |
Definition at line 666 of file serverpool.cpp.
|
inline |
Definition at line 92 of file serverpool.h.
Referenced by MythHTTPServer::EnableDisable(), and MediaServer::Init().
|
inline |
Definition at line 93 of file serverpool.h.
|
inline |
Definition at line 94 of file serverpool.h.
Referenced by HttpServer::HttpServer(), MythHTTPThreadPool::MythHTTPThreadPool(), and WebSocketServer::WebSocketServer().
|
inline |
Definition at line 95 of file serverpool.h.
Referenced by MythHTTPServer::EnableDisable().
|
inline |
Definition at line 97 of file serverpool.h.
|
inline |
Definition at line 98 of file serverpool.h.
Referenced by MythSocketManager::Listen(), and MainServer::MainServer().
void ServerPool::close | ( | void | ) |
Definition at line 368 of file serverpool.cpp.
Referenced by bind(), MythRAOPConnection::CleanUp(), MythUDPListener::DoEnable(), MythHTTPServer::EnableDisable(), MythSocketManager::Listen(), listen(), MythRAOPConnection::ProcessRequest(), LCDServer::shutDown(), MythRAOPConnection::~MythRAOPConnection(), and ~ServerPool().
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 722 of file serverpool.cpp.
Referenced by MythRAOPConnection::ProcessRequest(), MythRAOPDevice::Start(), and MythAirplayServer::Start().
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 755 of file serverpool.cpp.
Referenced by MythRAOPConnection::Init(), and MythRAOPConnection::ProcessRequest().
|
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 791 of file serverpool.cpp.
|
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 855 of file serverpool.cpp.
|
signal |
|
signal |
|
protectedvirtualslot |
Definition at line 690 of file serverpool.cpp.
Referenced by bind().
|
protectedvirtualslot |
Definition at line 672 of file serverpool.cpp.
Referenced by listen().
Definition at line 73 of file serverpool.cpp.
Referenced by DefaultBroadcastIPv4(), DefaultListenIPv4(), DefaultListenIPv6(), and RefreshDefaultListen().
Definition at line 121 of file serverpool.h.
Referenced by bind(), close(), listen(), and writeDatagram().
|
private |
Definition at line 122 of file serverpool.h.
Referenced by listen().
|
private |
Definition at line 123 of file serverpool.h.
|
private |
Definition at line 124 of file serverpool.h.
Referenced by listen().
|
private |
Definition at line 126 of file serverpool.h.
|
private |
Definition at line 127 of file serverpool.h.
Referenced by bind(), close(), and writeDatagram().
|
private |
Definition at line 128 of file serverpool.h.
Referenced by close(), and writeDatagram().