KNetwork::KResolver

Search for usage in LXR

#include <k3resolver.h>

Inheritance diagram for KNetwork::KResolver:

Public Types

enum  ErrorCodes {
  NoError = 0, AddrFamily = -1, TryAgain = -2, NonRecoverable = -3,
  BadFlags = -4, Memory = -5, NoName = -6, UnsupportedFamily = -7,
  UnsupportedService = -8, UnsupportedSocketType = -9, UnknownError = -10, SystemError = -11,
  Canceled = -100
}
 
enum  Flags {
  Passive = 0x01, CanonName = 0x02, NoResolve = 0x04, NoSrv = 0x08,
  Multiport = 0x10
}
 
enum  SocketFamilies {
  UnknownFamily = 0x0001, UnixFamily = 0x0002, LocalFamily = UnixFamily, IPv4Family = 0x0004,
  IPv6Family = 0x0008, InternetFamily = IPv4Family | IPv6Family, InetFamily = InternetFamily, KnownFamily = ~UnknownFamily,
  AnyFamily = KnownFamily | UnknownFamily
}
 
enum  StatusCodes {
  Idle = 0, Queued = 1, InProgress = 5, PostProcessing = 6,
  Success = 10, Failed = -101
}
 

Signals

void finished (const KNetwork::KResolverResults &results)
 

Public Member Functions

 KResolver (const QString &nodename, const QString &servicename=QString(), QObject *parent=nullptr)
 
 KResolver (QObject *parent=nullptr)
 
 ~KResolver () override
 
void cancel (bool emitSignal=true)
 
int error () const
 
QString errorString () const
 
bool event (QEvent *) override
 
int flags () const
 
bool isRunning () const
 
QString nodeName () const
 
KResolverResults results () const
 
QString serviceName () const
 
void setAddress (const QString &node, const QString &service)
 
void setFamily (int families)
 
int setFlags (int flags)
 
void setNodeName (const QString &nodename)
 
void setProtocol (int protonum, const char *name=nullptr)
 
void setServiceName (const QString &service)
 
void setSocketType (int type)
 
bool start ()
 
int status () const
 
int systemError () const
 
bool wait (int msec=0)
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
bool blockSignals (bool block)
 
const QObjectListchildren () const const
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectInfo ()
 
void dumpObjectInfo () const const
 
void dumpObjectTree ()
 
void dumpObjectTree () const const
 
QList< QByteArraydynamicPropertyNames () const const
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegExp &regExp, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
bool inherits (const char *className) const const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const const
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
QVariant property (const char *name) const const
 
 Q_CLASSINFO (Name, Value)
 
 Q_DISABLE_COPY (Class)
 
 Q_DISABLE_COPY_MOVE (Class)
 
 Q_DISABLE_MOVE (Class)
 
 Q_EMIT Q_EMIT
 
 Q_ENUM (...)
 
 Q_ENUM_NS (...)
 
 Q_ENUMS (...)
 
 Q_FLAG (...)
 
 Q_FLAG_NS (...)
 
 Q_FLAGS (...)
 
 Q_GADGET Q_GADGET
 
 Q_INTERFACES (...)
 
 Q_INVOKABLE Q_INVOKABLE
 
 Q_NAMESPACE Q_NAMESPACE
 
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 
 Q_OBJECT Q_OBJECT
 
 Q_PROPERTY (...)
 
 Q_REVISION Q_REVISION
 
 Q_SET_OBJECT_NAME (Object)
 
 Q_SIGNAL Q_SIGNAL
 
 Q_SIGNALS Q_SIGNALS
 
 Q_SLOT Q_SLOT
 
 Q_SLOTS Q_SLOTS
 
qFindChild (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QRegExp &regExp)
 
QList< T > qFindChildren (const QObject *obj, const QString &name)
 
qobject_cast (const QObject *object)
 
qobject_cast (QObject *object)
 
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const const
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds time, Qt::TimerType timerType)
 
QThreadthread () const const
 

Static Public Member Functions

static QByteArray domainToAscii (const QString &unicodeDomain)
 
static QString domainToUnicode (const QByteArray &asciiDomain)
 
static QString domainToUnicode (const QString &asciiDomain)
 
static QString errorString (int errorcode, int syserror=0)
 
static QString localHostName ()
 
static QString normalizeDomain (const QString &domain)
 
static QList< QByteArrayprotocolName (const char *protoname)
 
static QList< QByteArrayprotocolName (int protonum)
 
static int protocolNumber (const char *protoname)
 
static KResolverResults resolve (const QString &host, const QString &service, int flags=0, int families=KResolver::InternetFamily)
 
static bool resolveAsync (QObject *userObj, const char *userSlot, const QString &host, const QString &service, int flags=0, int families=KResolver::InternetFamily)
 
static QList< QByteArrayserviceName (const char *servname, const char *protoname)
 
static QList< QByteArrayserviceName (int port, const char *protoname)
 
static int servicePort (const char *servname, const char *protoname)
 
- Static Public Member Functions inherited from QObject
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 

Protected Member Functions

void setError (int errorcode, int systemerror=0)
 
virtual void virtual_hook (int id, void *data)
 
- Protected Member Functions inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
int receivers (const char *signal) const const
 
QObjectsender () const const
 
int senderSignalIndex () const const
 
virtual void timerEvent (QTimerEvent *event)
 

Additional Inherited Members

- Properties inherited from QObject
 objectName
 
- Public Attributes inherited from QObject
typedef QObjectList
 

Detailed Description

Name and service resolution class.

This class provides support for doing name-to-binary resolution for nodenames and service ports. You should use this class if you need specific resolution techniques when creating a socket or if you want to inspect the results before calling the socket functions.

You can either create an object and set the options you want in it or you can simply call the static member functions, which will create standard Resolver objects and dispatch the resolution for you. Normally, the static functions will be used, except in cases where specific options must be set.

A Resolver object defaults to the following:

  • address family: any address family
  • socket type: streaming socket
  • protocol: implementation-defined. Generally, TCP
  • host and service: unset
Author
Thiago Macieira thiag[email protected][email protected][email protected]e.org
Deprecated:
Use KSocketFactory or KLocalSocket instead

Definition at line 312 of file k3resolver.h.

Member Enumeration Documentation

◆ ErrorCodes

Error codes.

These are the possible error values that objects of this class may return. See errorString() for getting a string representation for these errors.

  • AddrFamily: Address family for the given nodename is not supported.
  • TryAgain: Temporary failure in name resolution. You should try again.
  • NonRecoverable: Non-recoverable failure in name resolution.
  • BadFlags: Invalid flags were given.
  • Memory: Memory allocation failure.
  • NoName: The specified name or service doesn't exist.
  • UnsupportedFamily: The requested socket family is not supported.
  • UnsupportedService: The requested service is not supported for this socket type (i.e., a datagram service in a streaming socket).
  • UnsupportedSocketType: The requested socket type is not supported.
  • UnknownError: An unknown, unexpected error occurred.
  • SystemError: A system error occurred. See systemError().
  • Canceled: This request was canceled by the user.

Definition at line 395 of file k3resolver.h.

◆ Flags

Flags for the resolution.

These flags are used for setting the resolution behaviour for this object:

  • Passive: resolve to a passive socket (i.e., one that can be used for binding to a local interface)
  • CanonName: request that the canonical name for the given nodename be found and recorded
  • NoResolve: request that no external resolution be performed. The given nodename and servicename will be resolved locally only.
  • NoSrv: don't try to use SRV-based name-resolution.
  • Multiport: the port/service argument is a list of port numbers and ranges. (future extension)
Note
SRV-based lookup and Multiport are not implemented yet.

Definition at line 366 of file k3resolver.h.

◆ SocketFamilies

Address family selection types.

These values can be OR-ed together to form a composite family selection.

  • UnknownFamily: a family that is unknown to the current implementation
  • KnownFamily: a family that is known to the implementation (the exact opposite of UnknownFamily)
  • AnyFamilies: any address family is acceptable
  • InternetFamily: an address for connecting to the Internet
  • InetFamily: alias for InternetFamily
  • IPv6Family: an IPv6 address only
  • IPv4Family: an IPv4 address only
  • UnixFamily: an address for the local Unix namespace (i.e., Unix sockets)
  • LocalFamily: alias for UnixFamily

Definition at line 334 of file k3resolver.h.

◆ StatusCodes

Status codes.

These are the possible status for a Resolver object. A value greater than zero indicates normal behaviour, while negative values either indicate failure or error.

  • Idle: resolution has not yet been started.
  • Queued: resolution is queued but not yet in progress.
  • InProgress: resolution is in progress.
  • PostProcessing: resolution is in progress.
  • Success: resolution is done; you can retrieve the results.
  • Canceled: request canceled by the user.
  • Failed: resolution is done, but failed.

Note: the status Canceled and the error code Canceled are the same.

Note 2: the status Queued and InProgress might not be distinguishable. Some implementations might not differentiate one from the other.

Definition at line 432 of file k3resolver.h.

Constructor & Destructor Documentation

◆ KResolver() [1/2]

KResolver::KResolver ( QObject parent = nullptr)

Default constructor.

Creates an empty Resolver object. You should set the wanted names and flags using the member functions before starting the name resolution.

Parameters
parentthe parent object (see QObject)

Definition at line 273 of file k3resolver.cpp.

◆ KResolver() [2/2]

KResolver::KResolver ( const QString nodename,
const QString servicename = QString(),
QObject parent = nullptr 
)
explicit

Constructor with host and service names.

Creates a Resolver object with the given host and service names. Flags are initialised to 0 and any address family will be accepted.

Parameters
nodenamethe host name we want resolved
servicenamethe service name associated, like "http"
parentthe parent object (see QObject)

Definition at line 279 of file k3resolver.cpp.

◆ ~KResolver()

KResolver::~KResolver ( )
override

Destructor.

When this object is deleted, it'll destroy all associated resources. If the resolution is still in progress, it will be canceled and the signal will not be emitted.

Definition at line 286 of file k3resolver.cpp.

Member Function Documentation

◆ cancel()

void KResolver::cancel ( bool  emitSignal = true)

Cancels a running request.

This function will cancel a running request. If the request is not currently running or queued, this function does nothing.

Note: if you tell the signal to be emitted, be aware that it might or might not be emitted before this function returns.

Parameters
emitSignalwhether to emit the finished() signal or not

Definition at line 482 of file k3resolver.cpp.

◆ domainToAscii()

QByteArray KResolver::domainToAscii ( const QString unicodeDomain)
static

Returns the domain name in an ASCII Compatible Encoding form, suitable for DNS lookups.

This is the base for International Domain Name support over the Internet.

Note this function may fail, in which case it'll return a null QByteArray. Reasons for failure include use of unknown code points (Unicode characters).

Note that the encoding is illegible and, thus, should not be presented to the user, except if requested.

Parameters
unicodeDomainthe domain name to be encoded
Returns
the ACE-encoded suitable for DNS queries if successful, a null QByteArray if failure.

Definition at line 1012 of file k3resolver.cpp.

◆ domainToUnicode() [1/2]

QString KResolver::domainToUnicode ( const QByteArray asciiDomain)
static

Does the inverse of domainToAscii() and return an Unicode domain name from the given ACE-encoded domain.

This function may fail if the given domain cannot be successfully converted back to Unicode. Reasons for failure include a malformed domain name or good ones whose reencoding back to ACE don't match the form given here (e.g., ACE-encoding of an already ASCII-compatible domain).

It is, however, guaranteed that domains returned by domainToAscii() will work.

Parameters
asciiDomainthe ACE-encoded domain name to be decoded
Returns
the Unicode representation of the given domain name if successful, the original string if not
Note
ACE = ASCII-Compatible Encoding, i.e., 7-bit

Definition at line 1018 of file k3resolver.cpp.

◆ domainToUnicode() [2/2]

QString KResolver::domainToUnicode ( const QString asciiDomain)
static

The same as above, but taking a QString argument.

Parameters
asciiDomainthe ACE-encoded domain name to be decoded
Returns
the Unicode representation of the given domain name if successful, QString() if not.

Definition at line 1024 of file k3resolver.cpp.

◆ error()

int KResolver::error ( ) const

Retrieve the error code in this object.

This function will return NoError if we are not in an error condition. See status() and StatusCodes to find out what the current status is.

See also
errorString for getting a textual representation of this error

Definition at line 299 of file k3resolver.cpp.

◆ errorString() [1/2]

QString KResolver::errorString ( ) const

Returns the textual representation of the error in this object.

Definition at line 310 of file k3resolver.cpp.

◆ errorString() [2/2]

QString KResolver::errorString ( int  errorcode,
int  syserror = 0 
)
static

Returns the string representation of this error code.

Parameters
errorcodethe error code. See ErrorCodes.
syserrorthe system error code associated.
Returns
the string representation. This is already i18n'ed.

Definition at line 529 of file k3resolver.cpp.

◆ event()

bool KResolver::event ( QEvent e)
overridevirtual

Handles events.

Reimplemented from QObject.

This function handles the events generated by the manager indicating that this object has finished processing.

Do not post events to this object.

Reimplemented from QObject.

Definition at line 504 of file k3resolver.cpp.

◆ finished

void KNetwork::KResolver::finished ( const KNetwork::KResolverResults results)
signal

This signal is emitted whenever the resolution is finished, one way or another (success or failure).

The results parameter will contain the resolved data.

Note: if you are doing multiple resolutions, you can use the QObject::sender() function to distinguish one Resolver object from another.

Parameters
resultsthe resolved data; might be empty if the resolution failed
See also
results for information on what the results are
Note
This signal is always delivered in the GUI event thread, even for resolutions that were started in secondary threads.

◆ flags()

int KResolver::flags ( ) const

Retrieves the flags set for the resolution.

See also
Flags for an explanation on what flags are possible

Definition at line 363 of file k3resolver.cpp.

◆ isRunning()

bool KResolver::isRunning ( ) const

Returns true if this object is currently running.

Definition at line 316 of file k3resolver.cpp.

◆ localHostName()

QString KResolver::localHostName ( )
static

Returns this machine's local hostname.

Returns
this machine's local hostname

Definition at line 948 of file k3resolver.cpp.

◆ nodeName()

QString KResolver::nodeName ( ) const

The nodename to which the resolution was/is to be performed.

Definition at line 322 of file k3resolver.cpp.

◆ normalizeDomain()

QString KResolver::normalizeDomain ( const QString domain)
static

Normalise a domain name.

In order to prevent simple mistakes in International Domain Names (IDN), it has been decided that certain code points (characters in Unicode) would be instead converted to others. This includes turning them all to lower case, as well certain other specific operations, as specified in the documents.

For instance, the German 'ß' will be changed into 'ss', while the micro symbol 'µ' will be changed to the Greek mu 'μ'.

Two equivalent domains have the same normalised form. And the normalised form of a normalised domain is itself (i.e., if d is normalised, the following is true: d == normalizeDomain(d) )

This operation is equivalent to encoding and the decoding a Unicode hostname.

Parameters
domaina domain to be normalised
Returns
the normalised domain, or QString() if the domain is invalid.

Definition at line 1033 of file k3resolver.cpp.

◆ protocolName() [1/2]

QList< QByteArray > KResolver::protocolName ( const char *  protoname)
static

Finds all aliases for a given protocol name.

Parameters
protonamethe protocol name to be looked for
Returns
all the protocol names in a list. The first is the "proper" name.

Definition at line 658 of file k3resolver.cpp.

◆ protocolName() [2/2]

QList< QByteArray > KResolver::protocolName ( int  protonum)
static

Resolves a protocol number to its names.

Note: the returned QStrList operates on deep-copies.

Parameters
protonumthe protocol number to be looked for
Returns
all the protocol names in a list. The first is the "proper" name.

Definition at line 599 of file k3resolver.cpp.

◆ protocolNumber()

int KResolver::protocolNumber ( const char *  protoname)
static

Resolves a protocol name to its number.

Parameters
protonamethe protocol name to be looked for
Returns
the protocol number or -1 if we couldn't locate it

Definition at line 717 of file k3resolver.cpp.

◆ resolve()

KResolverResults KResolver::resolve ( const QString host,
const QString service,
int  flags = 0,
int  families = KResolver::InternetFamily 
)
static

Resolve the nodename and service name synchronously.

This static function is provided as convenience for simplifying name resolution. It resolves the given host and service names synchronously and returns the results it found. It is equivalent to the following code:

KResolver qres(host, service);
qres.setFlags(flags);
qres.setFamily(families)
qres.start();
qres.wait();
return qres.results();
Parameters
hostthe nodename to resolve
servicethe service to resolve
flagsflags to be used
familiesthe families to be searched
Returns
a KResolverResults object containing the results
See also
KResolverResults for information on how to obtain the error code

Definition at line 573 of file k3resolver.cpp.

◆ resolveAsync()

bool KResolver::resolveAsync ( QObject userObj,
const char *  userSlot,
const QString host,
const QString service,
int  flags = 0,
int  families = KResolver::InternetFamily 
)
static

Start an asynchronous name resolution.

This function is provided as a convenience to simplify the resolution process. It creates an internal KResolver object, connects the finished() signal to the given slot and starts the resolution asynchronously. It is more or less equivalent to the following code:

Note: this function may trigger the signal before it returns, so your code must be prepared for this situation.

KResolver* qres = new KResolver(host, service);
userObj, userSlot);
qres->setFlags(flags);
qres->setFamily(families);
return qres->start();

You should use it like this in your code:

KResolver::resolveAsync(myObj, SLOT(mySlot(KResolverResults)), host, service);
Parameters
userObjthe object whose slot userSlot we will connect
userSlotthe slot to which we'll connect
hostthe nodename to resolve
servicethe service to resolve
flagsflags to be used
familiesfamilies to be searcheed
Returns
true if the queuing was successful, false if not
See also
KResolverResults for information on how to obtain the error code

Definition at line 585 of file k3resolver.cpp.

◆ results()

KResolverResults KResolver::results ( ) const

Retrieves the results of this resolution.

Use this function to retrieve the results of the resolution. If no data was resolved (yet) or if we failed, this function will return an empty object.

Returns
the resolved data
See also
status for information on finding out if the resolution was successful

Definition at line 491 of file k3resolver.cpp.

◆ serviceName() [1/3]

QString KResolver::serviceName ( ) const

The service name to which the resolution was/is to be performed.

Definition at line 328 of file k3resolver.cpp.

◆ serviceName() [2/3]

QList< QByteArray > KResolver::serviceName ( const char *  servname,
const char *  protoname 
)
static

Finds all the aliases for a given service name.

Note: the returned QList<QByteArray> operates on deep-copies.

Parameters
servnamethe service alias to be looked for
protonamethe protocol it is associated with
Returns
all the service names in a list. The first is the "proper" name.

Definition at line 830 of file k3resolver.cpp.

◆ serviceName() [3/3]

QList< QByteArray > KResolver::serviceName ( int  port,
const char *  protoname 
)
static

Resolves a port number to its names.

Note: the returned QList<QByteArray> operates on deep copies.

Parameters
portthe port number, in host byte-order
protonamethe protocol it is associated with
Returns
all the service names in a list. The first is the "proper" name.

Definition at line 889 of file k3resolver.cpp.

◆ servicePort()

int KResolver::servicePort ( const char *  servname,
const char *  protoname 
)
static

Resolves a service name to its port number.

Parameters
servnamethe service name to be looked for
protonamethe protocol it is associated with
Returns
the port number in host byte-order or -1 in case of error

Definition at line 774 of file k3resolver.cpp.

◆ setAddress()

void KResolver::setAddress ( const QString node,
const QString service 
)

Sets both the host and the service names.

Setting either value to QString() will unset them.

Parameters
nodeThe nodename
serviceThe service name

Definition at line 356 of file k3resolver.cpp.

◆ setError()

void KNetwork::KResolver::setError ( int  errorcode,
int  systemerror = 0 
)
protected

Sets the error codes.

◆ setFamily()

void KResolver::setFamily ( int  families)

Sets the allowed socket families.

Parameters
familiesthe families that we want/accept
See also
SocketFamilies for possible values

Definition at line 380 of file k3resolver.cpp.

◆ setFlags()

int KResolver::setFlags ( int  flags)

Sets the flags.

Parameters
flagsthe new flags
Returns
the old flags
See also
Flags for an explanation on the flags

Definition at line 369 of file k3resolver.cpp.

◆ setNodeName()

void KResolver::setNodeName ( const QString nodename)

Sets the nodename for the resolution.

Set the nodename to QString() to unset it.

Parameters
nodenameThe nodename to be resolved.

Definition at line 334 of file k3resolver.cpp.

◆ setProtocol()

void KResolver::setProtocol ( int  protonum,
const char *  name = nullptr 
)

Sets the protocol we want.

Protocols are dependent on the selected address family, so you should know what you are doing if you use this function. Besides, protocols generally are either stream-based or datagram-based, so the value of the socket type is also important. The resolution will fail if these values don't match.

When using an Internet socket, the values for the protocol are the IPPROTO_* constants, defined in <netinet/in.h>.

You may choose to set the protocol either by its number or by its name, or by both. If you set:

  • the number and the name: both values will be stored internally; you may set the name to an empty value, if wanted
  • the number only (name = NULL): the name will be searched in the protocols database
  • the name only (number = 0): the number will be searched in the database
  • neither name nor number: reset to default behaviour
Parameters
protonumthe protocol number we want
namethe protocol name

Definition at line 398 of file k3resolver.cpp.

◆ setServiceName()

void KResolver::setServiceName ( const QString service)

Sets the service name to be resolved.

Set it to QString() to unset it.

Parameters
serviceThe service to be resolved.

Definition at line 345 of file k3resolver.cpp.

◆ setSocketType()

void KResolver::setSocketType ( int  type)

Sets the socket type we want.

The values for the type parameter are the SOCK_* constants, defined in <sys/socket.h>. The most common values are:

  • SOCK_STREAM streaming socket (= reliable, sequenced, connection-based)
  • SOCK_DGRAM datagram socket (= unreliable, connectionless)
  • SOCK_RAW raw socket, with direct access to the container protocol (such as IP)

These three are the only values to which it is guaranteed that resolution will work. Some systems may define other constants (such as SOCK_RDM for reliable datagrams), but support is implementation-defined.

Parameters
typethe wanted socket type (SOCK_* constants). Set 0 to use the default.

Definition at line 389 of file k3resolver.cpp.

◆ start()

bool KResolver::start ( )

Starts the name resolution asynchronously.

This function will queue this object for resolution and will return immediately. The status upon exit will either be Queued or InProgress or Failed.

This function does nothing if the object is already queued. But if it had already succeeded or failed, this function will re-start it.

Note: if both the nodename and the servicename are unset, this function will not queue, but will set a success state and emit the signal. Also note that in this case and maybe others, the signal finished() might be emitted before this function returns.

Returns
true if this request was successfully queued for asynchronous resolution

Definition at line 419 of file k3resolver.cpp.

◆ status()

int KResolver::status ( ) const

Retrieve the current status of this object.

See also
StatusCodes for the possible status codes.

Definition at line 293 of file k3resolver.cpp.

◆ systemError()

int KResolver::systemError ( ) const

Retrieve the associated system error code in this object.

Many resolution operations may generate an extra error code as given by the C errno variable. That value is stored in the object and can be retrieved by this function.

Definition at line 305 of file k3resolver.cpp.

◆ virtual_hook()

void KResolver::virtual_hook ( int  id,
void *  data 
)
protectedvirtual

Standard hack to add virtuals later.

Definition at line 1038 of file k3resolver.cpp.

◆ wait()

bool KResolver::wait ( int  msec = 0)

Waits for a request to finish resolving.

This function will wait on a running request for its termination. The status upon exit will either be Success or Failed or Canceled.

This function may be called from any thread, even one that is not the GUI thread or the one that started the resolution process. But note this function is not thread-safe nor reentrant: i.e., only one thread can be waiting on one given object.

Also note that this function ensures that the finished() signal is emitted before it returns. That means that, as a side-effect, whenever wait() is called, the signal is emitted on the thread calling wait().

Parameters
msecthe time to wait, in milliseconds or 0 to wait forever
Returns
true if the resolution has finished processing, even when it failed or was canceled. False means the wait timed out and the resolution is still running.

Definition at line 436 of file k3resolver.cpp.


The documentation for this class was generated from the following files:
Name and service resolution results.
Definition: k3resolver.h:212
int flags() const
Retrieves the flags set for the resolution.
Definition: k3resolver.cpp:363
static bool resolveAsync(QObject *userObj, const char *userSlot, const QString &host, const QString &service, int flags=0, int families=KResolver::InternetFamily)
Start an asynchronous name resolution.
Definition: k3resolver.cpp:585
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KResolver(QObject *parent=nullptr)
Default constructor.
Definition: k3resolver.cpp:273
void finished(const KNetwork::KResolverResults &results)
This signal is emitted whenever the resolution is finished, one way or another (success or failure).
ScriptableExtension * host() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon May 8 2023 03:56:02 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.