MythTV master
Public Slots | Public 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 (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}
 

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

◆ 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 258 of file portchecker.cpp.

Referenced by MythContext::Impl::checkPort().

◆ 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.

Parameters
hostHost id or ip address (IPV4 or IPV6).
portPort number to check.
timeLimitlimit in milliseconds for testing.
Returns
true if the port could be contacted.

Definition at line 63 of file portchecker.cpp.

Referenced by SSDPCache::Add(), and MythContext::Impl::checkPort().

◆ resolveLinkLocal()

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.

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 140 of file portchecker.cpp.

Referenced by checkPort(), MythSocket::ConnectToHostReal(), MSqlDatabase::OpenDatabase(), and MythContext::Impl::TestDBconnection().

Member Data Documentation

◆ m_cancelCheck

bool PortChecker::m_cancelCheck {false}
private

Definition at line 60 of file portchecker.h.

Referenced by cancelPortCheck(), checkPort(), and resolveLinkLocal().


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