File indexing completed on 2026-10-04 09:19:28
0001
0002
0003
0004
0005 #ifndef QSOCKETNOTIFIER_H
0006 #define QSOCKETNOTIFIER_H
0007
0008 #include <QtCore/qobject.h>
0009
0010 QT_BEGIN_NAMESPACE
0011
0012 class QSocketDescriptor;
0013 class QSocketNotifierPrivate;
0014 class Q_CORE_EXPORT QSocketNotifier : public QObject
0015 {
0016 Q_OBJECT
0017 Q_DECLARE_PRIVATE(QSocketNotifier)
0018
0019 public:
0020 enum Type { Read, Write, Exception };
0021
0022 explicit QSocketNotifier(Type, QObject *parent = nullptr);
0023 QSocketNotifier(qintptr socket, Type, QObject *parent = nullptr);
0024 ~QSocketNotifier();
0025
0026 void setSocket(qintptr socket);
0027 qintptr socket() const;
0028 Type type() const;
0029
0030 bool isValid() const;
0031 bool isEnabled() const;
0032
0033 public Q_SLOTS:
0034 void setEnabled(bool);
0035
0036 Q_SIGNALS:
0037 #if defined(Q_MOC_RUN)
0038
0039
0040
0041 void activated(QSocketDescriptor socket, QSocketNotifier::Type activationEvent = Read,
0042 QPrivateSignal = {});
0043 #else
0044 void activated(QSocketDescriptor socket, QSocketNotifier::Type activationEvent, QPrivateSignal);
0045 #endif
0046
0047
0048
0049
0050
0051 #if defined(Q_MOC_RUN) || defined(BUILDING_QSOCKETNOTIFIER) || defined(Q_QDOC)
0052 QT_MOC_COMPAT void activated(int socket, QPrivateSignal);
0053 #endif
0054
0055 protected:
0056 bool event(QEvent *) override;
0057
0058 private:
0059 Q_DISABLE_COPY(QSocketNotifier)
0060 };
0061
0062 class QSocketDescriptor
0063 {
0064 public:
0065 #if defined(Q_OS_WIN) || defined(Q_QDOC)
0066 using DescriptorType = Qt::HANDLE;
0067 #define Q_DECL_CONSTEXPR_NOT_WIN
0068 #else
0069 using DescriptorType = int;
0070 #define Q_DECL_CONSTEXPR_NOT_WIN Q_DECL_CONSTEXPR
0071 #endif
0072
0073 Q_DECL_CONSTEXPR_NOT_WIN Q_IMPLICIT
0074 QSocketDescriptor(DescriptorType descriptor = DescriptorType(-1)) noexcept : sockfd(descriptor)
0075 {
0076 }
0077
0078 #if defined(Q_OS_WIN) || defined(Q_QDOC)
0079 Q_IMPLICIT QSocketDescriptor(qintptr desc) noexcept : sockfd(DescriptorType(desc)) {}
0080 Q_IMPLICIT operator qintptr() const noexcept { return qintptr(sockfd); }
0081 Q_DECL_CONSTEXPR Qt::HANDLE winHandle() const noexcept { return sockfd; }
0082 #endif
0083 Q_DECL_CONSTEXPR operator DescriptorType() const noexcept { return sockfd; }
0084
0085 Q_DECL_CONSTEXPR_NOT_WIN bool isValid() const noexcept { return *this != QSocketDescriptor(); }
0086
0087 private:
0088 friend Q_DECL_CONSTEXPR_NOT_WIN bool comparesEqual(const QSocketDescriptor &lhs,
0089 const QSocketDescriptor &rhs) noexcept
0090 {
0091 return lhs.sockfd == rhs.sockfd;
0092 }
0093 #if defined(Q_OS_WIN) || defined(Q_QDOC)
0094 Q_DECLARE_EQUALITY_COMPARABLE(QSocketDescriptor)
0095 #else
0096 Q_DECLARE_EQUALITY_COMPARABLE_LITERAL_TYPE(QSocketDescriptor)
0097 #endif
0098
0099 #undef Q_DECL_CONSTEXPR_NOT_WIN
0100
0101 DescriptorType sockfd;
0102 };
0103
0104 QT_END_NAMESPACE
0105
0106 QT_DECL_METATYPE_EXTERN_TAGGED(QSocketNotifier::Type, QSocketNotifier_Type, Q_CORE_EXPORT)
0107 QT_DECL_METATYPE_EXTERN(QSocketDescriptor, Q_CORE_EXPORT)
0108
0109 #endif