MythTV
master
|
Small class to handle TCP port checking and finding link-local context. More...
#include <libmythbase/portchecker.h>
Public Slots | |
void | cancelPortCheck (void) |
Cancel the checkPort operation currently in progress. More... | |
Public Member Functions | |
PortChecker ()=default | |
~PortChecker () override=default | |
bool | checkPort (QString &host, int port, std::chrono::milliseconds timeLimit=30s, bool linkLocalOnly=false) |
Check if a port is open and sort out the link-local scope. More... | |
Static Public Member Functions | |
static bool | resolveLinkLocal (QString &host, int port, std::chrono::milliseconds timeLimit=30s) |
Convenience method to resolve link-local address. More... | |
Static Private Member Functions | |
static void | processEvents (void) |
Private Attributes | |
bool | m_cancelCheck {false} |
Small class to handle TCP port checking and finding link-local context.
Create an automatic object when needed to perform port checks. It is not thread safe and must not be called recursively. Using an automatic object is the safest way. You can use the same object again to perform a second, third, ..., check.
Definition at line 44 of file portchecker.h.
|
default |
|
overridedefault |
bool PortChecker::checkPort | ( | QString & | host, |
int | port, | ||
std::chrono::milliseconds | timeLimit = 30s , |
||
bool | linkLocalOnly = false |
||
) |
Check if a port is open and sort out the link-local scope.
Checks the specified port repeatedly until either it connects or the time limit is reached
This routine also finds the correct scope id in case of an IPV6 link-local address, and caches it in gCoreContext->SetScopeForAddress
If linkLocalOnly is specified, it only obtains link-local address scope. In this case, the port is not checked unless needed to find the scope. This will also return after 1 check of all available interfaces. If will not repeatedly check the port. To make sure all interfaces are checked, make sure enough time is allowed, up to 3 seconds for each interface checked.
For Windows build, link local address is not checked as windows does not require the scope id.
This routine does call event processor, so the GUI can be responsive on the same thread.
host | [in,out] Host id or ip address (IPV4 or IPV6). This is updated with scope if the address is link-local IPV6. |
port | Port number to check. |
timeLimit | limit in milliseconds for testing. |
linkLocalOnly | Only obtain Link-local address scope. |
Definition at line 73 of file portchecker.cpp.
Referenced by SSDPCache::Add(), MythContextPrivate::checkPort(), and resolveLinkLocal().
|
static |
Convenience method to resolve link-local address.
Update a host id to include the correct scope if it is link-local. If this is called with anything that is not a link-local address, it remains unchanged.
host | [in,out] Host id or ip address (IPV4 or IPV6). This is updated with scope if the address is link-local IPV6. |
port | Port number to check. |
timeLimit | limit in milliseconds for testing. |
Definition at line 230 of file portchecker.cpp.
Referenced by MythSocket::ConnectToHostReal(), and MSqlDatabase::OpenDatabase().
|
slot |
Cancel the checkPort operation currently in progress.
This is a slot that can be used by a GUI to stop port check operation in progress in case the user wants to cancel it.
Definition at line 249 of file portchecker.cpp.
Referenced by MythContextPrivate::checkPort().
|
staticprivate |
Definition at line 236 of file portchecker.cpp.
Referenced by checkPort().
Definition at line 61 of file portchecker.h.
Referenced by cancelPortCheck(), and checkPort().