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

Small class to handle TCP port checking and finding link-local context. More...

#include <libmythbase/portchecker.h>

Inheritance diagram for PortChecker:
[legend]
Collaboration diagram for PortChecker:
[legend]

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}
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ PortChecker()

PortChecker::PortChecker ( )
default

◆ ~PortChecker()

PortChecker::~PortChecker ( )
overridedefault

Member Function Documentation

◆ checkPort()

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.

Parameters
host[in,out] Host id or ip address (IPV4 or IPV6). This is updated with scope if the address is link-local IPV6.
portPort number to check.
timeLimitlimit in milliseconds for testing.
linkLocalOnlyOnly obtain Link-local address scope.
Returns
true if the port could be contacted. In the case of linkLocalOnly, return true if it was link local and was changed, false in other cases.

Definition at line 73 of file portchecker.cpp.

Referenced by SSDPCache::Add(), MythContextPrivate::checkPort(), and resolveLinkLocal().

◆ resolveLinkLocal()

bool PortChecker::resolveLinkLocal ( QString &  host,
int  port,
std::chrono::milliseconds  timeLimit = 30s 
)
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.

Parameters
host[in,out] Host id or ip address (IPV4 or IPV6). This is updated with scope if the address is link-local IPV6.
portPort number to check.
timeLimitlimit in milliseconds for testing.
Returns
true if it was link local and was resolved, false in other cases.

Definition at line 230 of file portchecker.cpp.

Referenced by MythSocket::ConnectToHostReal(), and MSqlDatabase::OpenDatabase().

◆ cancelPortCheck

void PortChecker::cancelPortCheck ( void  )
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().

◆ processEvents()

void PortChecker::processEvents ( void  )
staticprivate

Definition at line 236 of file portchecker.cpp.

Referenced by checkPort().

Member Data Documentation

◆ m_cancelCheck

bool PortChecker::m_cancelCheck {false}
private

Definition at line 61 of file portchecker.h.

Referenced by cancelPortCheck(), and checkPort().


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