Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qnativesocketengine_p_p.h
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// Copyright (C) 2016 Intel Corporation.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4// Qt-Security score:significant reason:default
5
6#ifndef QNATIVESOCKETENGINE_P_P_H
7#define QNATIVESOCKETENGINE_P_P_H
8
9//
10// W A R N I N G
11// -------------
12//
13// This file is not part of the Qt API. It exists purely as an
14// implementation detail. This header file may change from version to
15// version without notice, or even be removed.
16//
17// We mean it.
18//
19
20#include "private/qabstractsocketengine_p.h"
21#include "private/qnativesocketengine_p.h"
22
23#ifndef Q_OS_WIN
24# include <netinet/in.h>
25#else
26# include <winsock2.h>
27# include <ws2tcpip.h>
28# include <mswsock.h>
29#endif
30
31QT_BEGIN_NAMESPACE
32
33#ifdef Q_OS_WIN
34
35// The following definitions are copied from the MinGW header mswsock.h which
36// was placed in the public domain. The WSASendMsg and WSARecvMsg functions
37// were introduced with Windows Vista, so some Win32 headers are lacking them.
38// There are no known versions of Windows CE or Embedded that contain them.
39# ifndef WSAID_WSARECVMSG
40typedef INT (WINAPI *LPFN_WSARECVMSG)(SOCKET s, LPWSAMSG lpMsg,
41 LPDWORD lpdwNumberOfBytesRecvd,
42 LPWSAOVERLAPPED lpOverlapped,
43 LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine);
44# define WSAID_WSARECVMSG {0xf689d7c8,0x6f1f,0x436b,{0x8a,0x53,0xe5,0x4f,0xe3,0x51,0xc3,0x22}}
45# endif // !WSAID_WSARECVMSG
46# ifndef WSAID_WSASENDMSG
47typedef struct {
48 LPWSAMSG lpMsg;
49 DWORD dwFlags;
50 LPDWORD lpNumberOfBytesSent;
51 LPWSAOVERLAPPED lpOverlapped;
52 LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine;
53} WSASENDMSG, *LPWSASENDMSG;
54
55typedef INT (WSAAPI *LPFN_WSASENDMSG)(SOCKET s, LPWSAMSG lpMsg, DWORD dwFlags,
56 LPDWORD lpNumberOfBytesSent,
57 LPWSAOVERLAPPED lpOverlapped,
58 LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine);
59
60# define WSAID_WSASENDMSG {0xa441e712,0x754f,0x43ca,{0x84,0xa7,0x0d,0xee,0x44,0xcf,0x60,0x6d}}
61# endif // !WSAID_WSASENDMSG
62#endif // Q_OS_WIN
63
64union qt_sockaddr {
65 sockaddr a;
66 sockaddr_in a4;
67 sockaddr_in6 a6;
68};
69
70class QSocketNotifier;
71
73{
74 Q_DECLARE_PUBLIC(QNativeSocketEngine)
75public:
78
80
82
83#if defined(Q_OS_WIN)
86# endif
119
120 void setError(QAbstractSocket::SocketError error, ErrorString errorString) const;
121 QHostAddress adjustAddressProtocol(const QHostAddress &address) const;
122
123 // native functions
124 int option(QNativeSocketEngine::SocketOption option) const;
125 bool setOption(QNativeSocketEngine::SocketOption option, int value);
126
127 bool createNewSocket(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol &protocol);
128
129 bool nativeConnect(const QHostAddress &address, quint16 port);
130 bool nativeBind(const QHostAddress &address, quint16 port);
131 bool nativeListen(int backlog);
133#ifndef QT_NO_NETWORKINTERFACE
134 bool nativeJoinMulticastGroup(const QHostAddress &groupAddress,
135 const QNetworkInterface &iface);
136 bool nativeLeaveMulticastGroup(const QHostAddress &groupAddress,
137 const QNetworkInterface &iface);
139 bool nativeSetMulticastInterface(const QNetworkInterface &iface);
140#endif
142
143 bool nativeHasPendingDatagrams() const;
145 qint64 nativeReceiveDatagram(char *data, qint64 maxLength, QIpPacketHeader *header,
146 QAbstractSocketEngine::PacketHeaderOptions options);
147 qint64 nativeSendDatagram(const char *data, qint64 length, const QIpPacketHeader &header);
148 qint64 nativeRead(char *data, qint64 maxLength);
149 qint64 nativeWrite(const char *data, qint64 length);
150 int nativeSelect(QDeadlineTimer deadline, bool selectForRead) const;
151 int nativeSelect(QDeadlineTimer deadline, bool checkRead, bool checkWrite,
152 bool *selectForRead, bool *selectForWrite) const;
153
154 void nativeClose();
155
156 bool checkProxy(const QHostAddress &address);
158
159 /*! \internal
160 Sets \a address and \a port in the \a aa sockaddr structure and the size in \a sockAddrSize.
161 The address \a is converted to IPv6 if the current socket protocol is also IPv6.
162 */
163 void setPortAndAddress(quint16 port, const QHostAddress &address, qt_sockaddr *aa, QT_SOCKLEN_T *sockAddrSize)
164 {
165 switch (socketProtocol) {
166 case QHostAddress::IPv6Protocol:
167 case QHostAddress::AnyIPProtocol:
168 // force to IPv6
169 setSockaddr(&aa->a6, address, port);
170 *sockAddrSize = sizeof(sockaddr_in6);
171 return;
172
173 case QHostAddress::IPv4Protocol:
174 // force to IPv4
175 setSockaddr(&aa->a4, address, port);
176 *sockAddrSize = sizeof(sockaddr_in);
177 return;
178
179 case QHostAddress::UnknownNetworkLayerProtocol:
180 // don't force
181 break;
182 }
183 *sockAddrSize = setSockaddr(&aa->a, address, port);
184 }
185
186};
187
188QT_END_NAMESPACE
189
190#endif // QNATIVESOCKETENGINE_P_P_H
bool event(QEvent *) override
This virtual function receives events to an object and should return true if the event e was recogniz...
QExceptionNotifier(qintptr fd, QNativeSocketEngine *parent)
QNativeSocketEngine * engine
bool createNewSocket(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol &protocol)
QNetworkInterface nativeMulticastInterface() const
qint64 nativeWrite(const char *data, qint64 length)
int option(QNativeSocketEngine::SocketOption option) const
bool nativeJoinMulticastGroup(const QHostAddress &groupAddress, const QNetworkInterface &iface)
bool setOption(QNativeSocketEngine::SocketOption option, int value)
int nativeSelect(QDeadlineTimer deadline, bool selectForRead) const
void setError(QAbstractSocket::SocketError error, ErrorString errorString) const
bool nativeSetMulticastInterface(const QNetworkInterface &iface)
bool checkProxy(const QHostAddress &address)
bool fetchConnectionParameters()
Fetches information about both ends of the connection: whatever is available.
bool nativeBind(const QHostAddress &address, quint16 port)
qint64 nativeSendDatagram(const char *data, qint64 length, const QIpPacketHeader &header)
bool nativeConnect(const QHostAddress &address, quint16 port)
int nativeSelect(QDeadlineTimer deadline, bool checkRead, bool checkWrite, bool *selectForRead, bool *selectForWrite) const
void setPortAndAddress(quint16 port, const QHostAddress &address, qt_sockaddr *aa, QT_SOCKLEN_T *sockAddrSize)
bool nativeLeaveMulticastGroup(const QHostAddress &groupAddress, const QNetworkInterface &iface)
QHostAddress adjustAddressProtocol(const QHostAddress &address) const
qint64 nativeRead(char *data, qint64 maxLength)
qint64 nativeReceiveDatagram(char *data, qint64 maxLength, QIpPacketHeader *header, QAbstractSocketEngine::PacketHeaderOptions options)
The QNetworkProxyQuery class is used to query the proxy settings for a socket.
QNativeSocketEngine * engine
bool event(QEvent *) override
This virtual function receives events to an object and should return true if the event e was recogniz...
QReadNotifier(qintptr fd, QNativeSocketEngine *parent)
QWriteNotifier(qintptr fd, QNativeSocketEngine *parent)
QNativeSocketEngine * engine
bool event(QEvent *) override
\reimp
#define Q_CHECK_STATES3(function, state1, state2, state3, returnValue)
#define Q_CHECK_STATES(function, state1, state2, returnValue)
#define Q_CHECK_TYPES(function, type1, type2, returnValue)
#define Q_CHECK_VALID_SOCKETLAYER(function, returnValue)
#define Q_CHECK_NOT_STATE(function, checkState, returnValue)
#define Q_CHECK_TYPE(function, type, returnValue)
#define Q_CHECK_STATE(function, checkState, returnValue)