66 sin6->sin6_port = htons(port);
67 memcpy(sin6->sin6_addr.s6_addr, addr.toIPv6Address().c,
sizeof(sin6->sin6_addr));
68#if QT_CONFIG(networkinterface)
69 sin6->sin6_scope_id = QNetworkInterface::interfaceIndexFromName(addr.scopeId());
72 sin6->sin6_scope_id = addr.scopeId().toUInt();
79 switch (addr.protocol()) {
80 case QHostAddress::IPv4Protocol:
81 return setSockaddr(
reinterpret_cast<sockaddr_in *>(sa), addr, port);
83 case QHostAddress::IPv6Protocol:
84 case QHostAddress::AnyIPProtocol:
85 return setSockaddr(
reinterpret_cast<sockaddr_in6 *>(sa), addr, port);
87 case QHostAddress::UnknownNetworkLayerProtocol:
91 sa->sa_family = AF_UNSPEC;
105 QNativeSocketEngine(QObject *parent =
nullptr);
106 ~QNativeSocketEngine();
108 bool initialize(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol protocol = QAbstractSocket::IPv4Protocol) override;
109 bool initialize(qintptr socketDescriptor, QAbstractSocket::SocketState socketState = QAbstractSocket::ConnectedState) override;
111 qintptr socketDescriptor()
const override;
113 bool isValid()
const override;
115 bool connectToHost(
const QHostAddress &address, quint16 port) override;
116 bool connectToHostByName(
const QString &name, quint16 port) override;
117 bool bind(
const QHostAddress &address, quint16 port) override;
118 bool listen(
int backlog) override;
119 qintptr accept() override;
120 void close() override;
122 qint64 bytesAvailable()
const override;
124 qint64 read(
char *data, qint64 maxlen) override;
125 qint64 write(
const char *data, qint64 len) override;
127#ifndef QT_NO_UDPSOCKET
128#ifndef QT_NO_NETWORKINTERFACE
129 bool joinMulticastGroup(
const QHostAddress &groupAddress,
130 const QNetworkInterface &iface) override;
131 bool leaveMulticastGroup(
const QHostAddress &groupAddress,
132 const QNetworkInterface &iface) override;
133 QNetworkInterface multicastInterface()
const override;
134 bool setMulticastInterface(
const QNetworkInterface &iface) override;
137 bool hasPendingDatagrams()
const override;
138 qint64 pendingDatagramSize()
const override;
141 qint64 readDatagram(
char *data, qint64 maxlen, QIpPacketHeader * =
nullptr,
142 PacketHeaderOptions = WantNone) override;
143 qint64 writeDatagram(
const char *data, qint64 len,
const QIpPacketHeader &) override;
144 qint64 bytesToWrite()
const override;
147 qint64 receiveBufferSize()
const;
148 void setReceiveBufferSize(qint64 bufferSize);
150 qint64 sendBufferSize()
const;
151 void setSendBufferSize(qint64 bufferSize);
154 int option(SocketOption option)
const override;
155 bool setOption(SocketOption option,
int value) override;
157 bool waitForRead(QDeadlineTimer deadline = QDeadlineTimer{DefaultTimeout},
158 bool *timedOut =
nullptr) override;
159 bool waitForWrite(QDeadlineTimer deadline = QDeadlineTimer{DefaultTimeout},
160 bool *timedOut =
nullptr) override;
161 bool waitForReadOrWrite(
bool *readyToRead,
bool *readyToWrite,
162 bool checkRead,
bool checkWrite,
163 QDeadlineTimer deadline = QDeadlineTimer{DefaultTimeout},
164 bool *timedOut =
nullptr) override;
166 bool isReadNotificationEnabled()
const override;
167 void setReadNotificationEnabled(
bool enable) override;
168 bool isWriteNotificationEnabled()
const override;
169 void setWriteNotificationEnabled(
bool enable) override;
170 bool isExceptionNotificationEnabled()
const override;
171 void setExceptionNotificationEnabled(
bool enable) override;
175 void connectionNotification();
178 Q_DECLARE_PRIVATE(QNativeSocketEngine)
179 Q_DISABLE_COPY_MOVE(QNativeSocketEngine)