1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). |
4 | ** Contact: http://www.qt-project.org/legal |
5 | ** |
6 | ** This file is part of the QtNetwork module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and Digia. For licensing terms and |
14 | ** conditions see http://qt.digia.com/licensing. For further information |
15 | ** use the contact form at http://qt.digia.com/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 2.1 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
24 | ** |
25 | ** In addition, as a special exception, Digia gives you certain additional |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
28 | ** |
29 | ** GNU General Public License Usage |
30 | ** Alternatively, this file may be used under the terms of the GNU |
31 | ** General Public License version 3.0 as published by the Free Software |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the |
33 | ** packaging of this file. Please review the following information to |
34 | ** ensure the GNU General Public License version 3.0 requirements will be |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. |
36 | ** |
37 | ** |
38 | ** $QT_END_LICENSE$ |
39 | ** |
40 | ****************************************************************************/ |
41 | |
42 | #ifndef QLOCALSOCKET_H |
43 | #define QLOCALSOCKET_H |
44 | |
45 | #include <QtCore/qiodevice.h> |
46 | #include <QtNetwork/qabstractsocket.h> |
47 | |
48 | QT_BEGIN_HEADER |
49 | |
50 | QT_BEGIN_NAMESPACE |
51 | |
52 | QT_MODULE(Network) |
53 | |
54 | #ifndef QT_NO_LOCALSOCKET |
55 | |
56 | class QLocalSocketPrivate; |
57 | |
58 | class Q_NETWORK_EXPORT QLocalSocket : public QIODevice |
59 | { |
60 | Q_OBJECT |
61 | Q_DECLARE_PRIVATE(QLocalSocket) |
62 | |
63 | public: |
64 | enum LocalSocketError |
65 | { |
66 | ConnectionRefusedError = QAbstractSocket::ConnectionRefusedError, |
67 | PeerClosedError = QAbstractSocket::RemoteHostClosedError, |
68 | ServerNotFoundError = QAbstractSocket::HostNotFoundError, |
69 | SocketAccessError = QAbstractSocket::SocketAccessError, |
70 | SocketResourceError = QAbstractSocket::SocketResourceError, |
71 | SocketTimeoutError = QAbstractSocket::SocketTimeoutError, |
72 | DatagramTooLargeError = QAbstractSocket::DatagramTooLargeError, |
73 | ConnectionError = QAbstractSocket::NetworkError, |
74 | UnsupportedSocketOperationError = QAbstractSocket::UnsupportedSocketOperationError, |
75 | UnknownSocketError = QAbstractSocket::UnknownSocketError |
76 | }; |
77 | |
78 | enum LocalSocketState |
79 | { |
80 | UnconnectedState = QAbstractSocket::UnconnectedState, |
81 | ConnectingState = QAbstractSocket::ConnectingState, |
82 | ConnectedState = QAbstractSocket::ConnectedState, |
83 | ClosingState = QAbstractSocket::ClosingState |
84 | }; |
85 | |
86 | QLocalSocket(QObject *parent = 0); |
87 | ~QLocalSocket(); |
88 | |
89 | void connectToServer(const QString &name, OpenMode openMode = ReadWrite); |
90 | void disconnectFromServer(); |
91 | |
92 | QString serverName() const; |
93 | QString fullServerName() const; |
94 | |
95 | void abort(); |
96 | virtual bool isSequential() const; |
97 | virtual qint64 bytesAvailable() const; |
98 | virtual qint64 bytesToWrite() const; |
99 | virtual bool canReadLine() const; |
100 | virtual void close(); |
101 | LocalSocketError error() const; |
102 | bool flush(); |
103 | bool isValid() const; |
104 | qint64 readBufferSize() const; |
105 | void setReadBufferSize(qint64 size); |
106 | |
107 | bool setSocketDescriptor(quintptr socketDescriptor, |
108 | LocalSocketState socketState = ConnectedState, |
109 | OpenMode openMode = ReadWrite); |
110 | quintptr socketDescriptor() const; |
111 | |
112 | LocalSocketState state() const; |
113 | bool waitForBytesWritten(int msecs = 30000); |
114 | bool waitForConnected(int msecs = 30000); |
115 | bool waitForDisconnected(int msecs = 30000); |
116 | bool waitForReadyRead(int msecs = 30000); |
117 | |
118 | Q_SIGNALS: |
119 | void connected(); |
120 | void disconnected(); |
121 | void error(QLocalSocket::LocalSocketError socketError); |
122 | void stateChanged(QLocalSocket::LocalSocketState socketState); |
123 | |
124 | protected: |
125 | virtual qint64 readData(char*, qint64); |
126 | virtual qint64 writeData(const char*, qint64); |
127 | |
128 | private: |
129 | Q_DISABLE_COPY(QLocalSocket) |
130 | #if defined(QT_LOCALSOCKET_TCP) |
131 | Q_PRIVATE_SLOT(d_func(), void _q_stateChanged(QAbstractSocket::SocketState)) |
132 | Q_PRIVATE_SLOT(d_func(), void _q_error(QAbstractSocket::SocketError)) |
133 | #elif defined(Q_OS_WIN) |
134 | Q_PRIVATE_SLOT(d_func(), void _q_notified()) |
135 | Q_PRIVATE_SLOT(d_func(), void _q_canWrite()) |
136 | Q_PRIVATE_SLOT(d_func(), void _q_pipeClosed()) |
137 | Q_PRIVATE_SLOT(d_func(), void _q_emitReadyRead()) |
138 | #else |
139 | Q_PRIVATE_SLOT(d_func(), void _q_stateChanged(QAbstractSocket::SocketState)) |
140 | Q_PRIVATE_SLOT(d_func(), void _q_error(QAbstractSocket::SocketError)) |
141 | Q_PRIVATE_SLOT(d_func(), void _q_connectToSocket()) |
142 | Q_PRIVATE_SLOT(d_func(), void _q_abortConnectionAttempt()) |
143 | #endif |
144 | }; |
145 | |
146 | #ifndef QT_NO_DEBUG_STREAM |
147 | #include <QtCore/qdebug.h> |
148 | Q_NETWORK_EXPORT QDebug operator<<(QDebug, QLocalSocket::LocalSocketError); |
149 | Q_NETWORK_EXPORT QDebug operator<<(QDebug, QLocalSocket::LocalSocketState); |
150 | #endif |
151 | |
152 | #endif // QT_NO_LOCALSOCKET |
153 | |
154 | QT_END_NAMESPACE |
155 | |
156 | QT_END_HEADER |
157 | |
158 | #endif // QLOCALSOCKET_H |
159 | |