|
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 (const QString &host, int port, std::chrono::milliseconds timeLimit=30s) |
| Check if a port is open. More... | |
| bool | resolveLinkLocal (QString &host, int port, std::chrono::milliseconds timeLimit=30s) |
| Convenience method to resolve link-local address. More... | |
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 |
|
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 258 of file portchecker.cpp.
Referenced by MythContext::Impl::checkPort().
| bool PortChecker::checkPort | ( | const QString & | host, |
| int | port, | ||
| std::chrono::milliseconds | timeLimit = 30s |
||
| ) |
Check if a port is open.
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
This routine does call event processor, so the GUI can be responsive on the same thread.
| host | Host id or ip address (IPV4 or IPV6). |
| port | Port number to check. |
| timeLimit | limit in milliseconds for testing. |
Definition at line 63 of file portchecker.cpp.
Referenced by SSDPCache::Add(), and MythContext::Impl::checkPort().
| bool PortChecker::resolveLinkLocal | ( | QString & | host, |
| int | port, | ||
| std::chrono::milliseconds | timeLimit = 30s |
||
| ) |
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.
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
The port is not checked unless needed to find the scope. This will also return after 1 check of all available interfaces. It 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. |
Definition at line 140 of file portchecker.cpp.
Referenced by checkPort(), MythSocket::ConnectToHostReal(), MSqlDatabase::OpenDatabase(), and MythContext::Impl::TestDBconnection().
|
private |
Definition at line 60 of file portchecker.h.
Referenced by cancelPortCheck(), checkPort(), and resolveLinkLocal().