diff options
author | Morten Johan Sørvig <morten.sorvig@qt.io> | 2021-03-08 19:23:11 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-07-02 17:24:26 +0000 |
commit | 72c609203b48a684afe51878bd7bd487fe96a103 (patch) | |
tree | 6a992bebc7c326f46e28ecff97e76ef6f8d4d413 /src/corelib/kernel/qcfsocketnotifier.cpp | |
parent | 9d0bd169bbf950cca3705a8c855c82e236e928e8 (diff) |
macOS: Notify socket notifier on connection error6.0
Enable kCFSocketConnectCallBack to get connection made/failed
notifications. For the error case, the data pointer will be
set (it points to an int with the error code).
Change-Id: Ib51c0ae7c2c74d7bc2fea3c8b7aa9033a860f602
Fixes: QTBUG-91619
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
(cherry picked from commit d492245d9f98e410e1748f28a598945244dbafa8)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/corelib/kernel/qcfsocketnotifier.cpp')
-rw-r--r-- | src/corelib/kernel/qcfsocketnotifier.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/corelib/kernel/qcfsocketnotifier.cpp b/src/corelib/kernel/qcfsocketnotifier.cpp index 920ec9cd86..13fe30d0cd 100644 --- a/src/corelib/kernel/qcfsocketnotifier.cpp +++ b/src/corelib/kernel/qcfsocketnotifier.cpp @@ -48,7 +48,7 @@ QT_BEGIN_NAMESPACE Socket Notifiers *************************************************************************/ void qt_mac_socket_callback(CFSocketRef s, CFSocketCallBackType callbackType, CFDataRef, - const void *, void *info) + const void *data, void *info) { QCFSocketNotifier *cfSocketNotifier = static_cast<QCFSocketNotifier *>(info); @@ -61,7 +61,15 @@ void qt_mac_socket_callback(CFSocketRef s, CFSocketCallBackType callbackType, CF // notification after we've successfully disabled the CFSocket, but our Qt // notifier is now gone. The upshot is we have to check the notifier // every time. - if (callbackType == kCFSocketReadCallBack) { + if (callbackType == kCFSocketConnectCallBack) { + // The data pointer will be non-null on connection error + if (data) { + if (socketInfo->readNotifier) + QCoreApplication::sendEvent(socketInfo->readNotifier, ¬ifierEvent); + if (socketInfo->writeNotifier) + QCoreApplication::sendEvent(socketInfo->writeNotifier, ¬ifierEvent); + } + } else if (callbackType == kCFSocketReadCallBack) { if (socketInfo->readNotifier && socketInfo->readEnabled) { socketInfo->readEnabled = false; QCoreApplication::sendEvent(socketInfo->readNotifier, ¬ifierEvent); @@ -152,7 +160,7 @@ void QCFSocketNotifier::registerSocketNotifier(QSocketNotifier *notifier) // Create CFSocket, specify that we want both read and write callbacks (the callbacks // are enabled/disabled later on). - const int callbackTypes = kCFSocketReadCallBack | kCFSocketWriteCallBack; + const int callbackTypes = kCFSocketConnectCallBack | kCFSocketReadCallBack | kCFSocketWriteCallBack; CFSocketContext context = {0, this, 0, 0, 0}; socketInfo->socket = CFSocketCreateWithNative(kCFAllocatorDefault, nativeSocket, callbackTypes, qt_mac_socket_callback, &context); if (CFSocketIsValid(socketInfo->socket) == false) { |