Qt 4.8
qlocalsocket_p.h
Go to the documentation of this file.
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_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/qabstractsocketengine_p.h"
71 # include <qtcpsocket.h>
72 # include <qsocketnotifier.h>
73 # include <errno.h>
74 #endif
75 
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 
88  {
90  };
91 
92  inline void setErrorString(const QString &string)
93  {
95  }
96 
98  {
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 
115 {
117 
118 public:
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)
132  void destroyPipeHandles();
133  void setErrorString(const QString &function);
134  void _q_notified();
135  void _q_canWrite();
136  void _q_pipeClosed();
137  void _q_emitReadyRead();
138  DWORD checkPipeState();
139  void startAsyncRead();
140  bool completeAsyncRead();
141  void checkReadyRead();
143  OVERLAPPED overlapped;
153  static const qint64 initialReadBufferSize = 4096;
154 #else
155  QLocalUnixSocket unixSocket;
156  QString generateErrorString(QLocalSocket::LocalSocketError, const QString &function) const;
157  void errorOccurred(QLocalSocket::LocalSocketError, const QString &function);
158  void _q_stateChanged(QAbstractSocket::SocketState newState);
159  void _q_error(QAbstractSocket::SocketError newError);
160  void _q_connectToSocket();
161  void _q_abortConnectionAttempt();
162  void cancelDelayedConnect();
163  QSocketNotifier *delayConnect;
164  QTimer *connectTimer;
165  int connectingSocket;
166  QString connectingName;
167  QIODevice::OpenMode connectingOpenMode;
168 #endif
169 
173 };
174 
176 
177 #endif // QT_NO_LOCALSOCKET
178 
179 #endif // QLOCALSOCKET_P_H
180 
void setSocketError(SocketError socketError)
Sets the type of error that last occurred to socketError.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
LocalSocketState
This enum describes the different states in which a socket can be.
Definition: qlocalsocket.h:78
QWinEventNotifier * dataReadNotifier
qint64 readData(char *data, qint64 maxlen)
Reimplemented Function
#define error(msg)
QLocalSocket::LocalSocketState state
The QString class provides a Unicode character string.
Definition: qstring.h:83
QWindowsPipeWriter * pipeWriter
void setSocketState(SocketState state)
Sets the state of the socket to state.
QLocalSocket::LocalSocketError error
The QLocalSocket class provides a local socket.
Definition: qlocalsocket.h:58
The QSocketNotifier class provides support for monitoring activity on a file descriptor.
SocketState
This enum describes the different states in which a socket can be.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static bool init
SocketError
This enum describes the socket errors that can occur.
static const char * data(const QByteArray &arr)
The QTcpSocket class provides a TCP socket.
Definition: qtcpsocket.h:56
__int64 qint64
Definition: qglobal.h:942
void * HANDLE
Definition: qnamespace.h:1671
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
void setErrorString(const QString &errorString)
Sets the human readable description of the last device error that occurred to str.
Definition: qiodevice.cpp:1660
QRingBuffer readBuffer
qint64 writeData(const char *data, qint64 len)
Reimplemented Function
The QTimer class provides repetitive and single-shot timers.
Definition: qtimer.h:56
LocalSocketError
The LocalServerError enumeration represents the errors that can occur.
Definition: qlocalsocket.h:64