1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QLOCALSOCKET_P_H
6#define QLOCALSOCKET_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists for the convenience
13// of the QLocalSocket class. This header file may change from
14// version to version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtNetwork/private/qtnetworkglobal_p.h>
20
21#include "qlocalsocket.h"
22#include "private/qiodevice_p.h"
23
24#include <qtimer.h>
25
26QT_REQUIRE_CONFIG(localserver);
27
28#if defined(QT_LOCALSOCKET_TCP)
29# include "qtcpsocket.h"
30#elif defined(Q_OS_WIN)
31# include "private/qwindowspipereader_p.h"
32# include "private/qwindowspipewriter_p.h"
33# include <qwineventnotifier.h>
34#else
35# include "private/qabstractsocketengine_p.h"
36# include <qtcpsocket.h>
37# include <qsocketnotifier.h>
38# include <errno.h>
39#endif
40
41struct sockaddr_un;
42
43QT_BEGIN_NAMESPACE
44
45#if !defined(Q_OS_WIN) || defined(QT_LOCALSOCKET_TCP)
46
47class QLocalUnixSocket : public QTcpSocket
48{
49
50public:
51 QLocalUnixSocket() : QTcpSocket()
52 {
53 }
54
55 inline void setSocketState(QAbstractSocket::SocketState state)
56 {
57 QTcpSocket::setSocketState(state);
58 }
59
60 inline void setErrorString(const QString &string)
61 {
62 QTcpSocket::setErrorString(string);
63 }
64
65 inline void setSocketError(QAbstractSocket::SocketError error)
66 {
67 QTcpSocket::setSocketError(error);
68 }
69
70 inline qint64 readData(char *data, qint64 maxSize) override
71 {
72 return QTcpSocket::readData(data, maxlen: maxSize);
73 }
74
75 inline qint64 writeData(const char *data, qint64 maxSize) override
76 {
77 return QTcpSocket::writeData(data, len: maxSize);
78 }
79};
80#endif //#if !defined(Q_OS_WIN) || defined(QT_LOCALSOCKET_TCP)
81
82class QLocalSocketPrivate : public QIODevicePrivate
83{
84public:
85 Q_DECLARE_PUBLIC(QLocalSocket)
86
87 QLocalSocketPrivate();
88 void init();
89
90#if defined(QT_LOCALSOCKET_TCP)
91 QLocalUnixSocket* tcpSocket;
92 bool ownsTcpSocket;
93 void setSocket(QLocalUnixSocket*);
94 QString generateErrorString(QLocalSocket::LocalSocketError, const QString &function) const;
95 void setErrorAndEmit(QLocalSocket::LocalSocketError, const QString &function);
96 void _q_stateChanged(QAbstractSocket::SocketState newState);
97 void _q_errorOccurred(QAbstractSocket::SocketError newError);
98#elif defined(Q_OS_WIN)
99 ~QLocalSocketPrivate();
100 qint64 pipeWriterBytesToWrite() const;
101 void _q_canRead();
102 void _q_bytesWritten(qint64 bytes);
103 void _q_pipeClosed();
104 void _q_winError(ulong windowsError, const QString &function);
105 void _q_writeFailed();
106 HANDLE handle;
107 QWindowsPipeWriter *pipeWriter;
108 QWindowsPipeReader *pipeReader;
109 QLocalSocket::LocalSocketError error;
110#else
111 QLocalUnixSocket unixSocket;
112 QString generateErrorString(QLocalSocket::LocalSocketError, const QString &function) const;
113 void setErrorAndEmit(QLocalSocket::LocalSocketError, const QString &function);
114 void _q_stateChanged(QAbstractSocket::SocketState newState);
115 void _q_errorOccurred(QAbstractSocket::SocketError newError);
116 void _q_connectToSocket();
117 void _q_abortConnectionAttempt();
118 void cancelDelayedConnect();
119 void describeSocket(qintptr socketDescriptor);
120 static bool parseSockaddr(const sockaddr_un &addr, uint len,
121 QString &fullServerName, QString &serverName, bool &abstractNamespace);
122 QSocketNotifier *delayConnect;
123 QTimer *connectTimer;
124 QString connectingName;
125 int connectingSocket;
126 QIODevice::OpenMode connectingOpenMode;
127#endif
128 QLocalSocket::LocalSocketState state;
129 QString serverName;
130 QString fullServerName;
131#if defined(Q_OS_WIN) && !defined(QT_LOCALSOCKET_TCP)
132 bool emittedReadyRead;
133 bool emittedBytesWritten;
134#endif
135
136 Q_OBJECT_BINDABLE_PROPERTY(QLocalSocketPrivate, QLocalSocket::SocketOptions, socketOptions)
137};
138
139QT_END_NAMESPACE
140
141#endif // QLOCALSOCKET_P_H
142
143

source code of qtbase/src/network/socket/qlocalsocket_p.h