|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtNetwork module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #ifndef QLOCALSOCKET_P_H |
|
43 #define QLOCALSOCKET_P_H |
|
44 |
|
45 // |
|
46 // W A R N I N G |
|
47 // ------------- |
|
48 // |
|
49 // This file is not part of the Qt API. It exists for the convenience |
|
50 // of the QLocalSocket class. This header file may change from |
|
51 // version to version without notice, or even be removed. |
|
52 // |
|
53 // We mean it. |
|
54 // |
|
55 |
|
56 #ifndef QT_NO_LOCALSOCKET |
|
57 |
|
58 #include "qlocalsocket.h" |
|
59 #include "private/qiodevice_p.h" |
|
60 |
|
61 #include <qtimer.h> |
|
62 |
|
63 #if defined(QT_LOCALSOCKET_TCP) |
|
64 # include "qtcpsocket.h" |
|
65 #elif defined(Q_OS_WIN) |
|
66 # include "private/qwindowspipewriter_p.h" |
|
67 # include "private/qringbuffer_p.h" |
|
68 # include <private/qwineventnotifier_p.h> |
|
69 #else |
|
70 # include "private/qnativesocketengine_p.h" |
|
71 # include <qtcpsocket.h> |
|
72 # include <qsocketnotifier.h> |
|
73 # include <errno.h> |
|
74 #endif |
|
75 |
|
76 QT_BEGIN_NAMESPACE |
|
77 |
|
78 #if !defined(Q_OS_WIN) || defined(QT_LOCALSOCKET_TCP) |
|
79 class QLocalUnixSocket : public QTcpSocket |
|
80 { |
|
81 |
|
82 public: |
|
83 QLocalUnixSocket() : QTcpSocket() |
|
84 { |
|
85 }; |
|
86 |
|
87 inline void setSocketState(QAbstractSocket::SocketState state) |
|
88 { |
|
89 QTcpSocket::setSocketState(state); |
|
90 }; |
|
91 |
|
92 inline void setErrorString(const QString &string) |
|
93 { |
|
94 QTcpSocket::setErrorString(string); |
|
95 } |
|
96 |
|
97 inline void setSocketError(QAbstractSocket::SocketError error) |
|
98 { |
|
99 QTcpSocket::setSocketError(error); |
|
100 } |
|
101 |
|
102 inline qint64 readData(char *data, qint64 maxSize) |
|
103 { |
|
104 return QTcpSocket::readData(data, maxSize); |
|
105 } |
|
106 |
|
107 inline qint64 writeData(const char *data, qint64 maxSize) |
|
108 { |
|
109 return QTcpSocket::writeData(data, maxSize); |
|
110 } |
|
111 }; |
|
112 #endif //#if !defined(Q_OS_WIN) || defined(QT_LOCALSOCKET_TCP) |
|
113 |
|
114 class QLocalSocketPrivate : public QIODevicePrivate |
|
115 { |
|
116 Q_DECLARE_PUBLIC(QLocalSocket) |
|
117 |
|
118 public: |
|
119 QLocalSocketPrivate(); |
|
120 void init(); |
|
121 |
|
122 #if defined(QT_LOCALSOCKET_TCP) |
|
123 QLocalUnixSocket* tcpSocket; |
|
124 bool ownsTcpSocket; |
|
125 void setSocket(QLocalUnixSocket*); |
|
126 QString generateErrorString(QLocalSocket::LocalSocketError, const QString &function) const; |
|
127 void errorOccurred(QLocalSocket::LocalSocketError, const QString &function); |
|
128 void _q_stateChanged(QAbstractSocket::SocketState newState); |
|
129 void _q_error(QAbstractSocket::SocketError newError); |
|
130 #elif defined(Q_OS_WIN) |
|
131 ~QLocalSocketPrivate() { |
|
132 CloseHandle(overlapped.hEvent); |
|
133 } |
|
134 |
|
135 void setErrorString(const QString &function); |
|
136 void _q_notified(); |
|
137 void _q_canWrite(); |
|
138 void _q_pipeClosed(); |
|
139 void _q_emitReadyRead(); |
|
140 DWORD bytesAvailable(); |
|
141 void startAsyncRead(); |
|
142 bool completeAsyncRead(); |
|
143 void checkReadyRead(); |
|
144 HANDLE handle; |
|
145 OVERLAPPED overlapped; |
|
146 QWindowsPipeWriter *pipeWriter; |
|
147 qint64 readBufferMaxSize; |
|
148 QRingBuffer readBuffer; |
|
149 int actualReadBufferSize; |
|
150 QWinEventNotifier *dataReadNotifier; |
|
151 QLocalSocket::LocalSocketError error; |
|
152 bool readSequenceStarted; |
|
153 bool pendingReadyRead; |
|
154 bool pipeClosed; |
|
155 static const qint64 initialReadBufferSize = 4096; |
|
156 #else |
|
157 QLocalUnixSocket unixSocket; |
|
158 QString generateErrorString(QLocalSocket::LocalSocketError, const QString &function) const; |
|
159 void errorOccurred(QLocalSocket::LocalSocketError, const QString &function); |
|
160 void _q_stateChanged(QAbstractSocket::SocketState newState); |
|
161 void _q_error(QAbstractSocket::SocketError newError); |
|
162 void _q_connectToSocket(); |
|
163 void _q_abortConnectionAttempt(); |
|
164 void cancelDelayedConnect(); |
|
165 QSocketNotifier *delayConnect; |
|
166 QTimer *connectTimer; |
|
167 int connectingSocket; |
|
168 QString connectingName; |
|
169 QIODevice::OpenMode connectingOpenMode; |
|
170 #endif |
|
171 |
|
172 QString serverName; |
|
173 QString fullServerName; |
|
174 QLocalSocket::LocalSocketState state; |
|
175 }; |
|
176 |
|
177 QT_END_NAMESPACE |
|
178 |
|
179 #endif // QT_NO_LOCALSOCKET |
|
180 |
|
181 #endif // QLOCALSOCKET_P_H |
|
182 |