Qt 4.8
qlocalsocket.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_H
43 #define QLOCALSOCKET_H
44 
45 #include <QtCore/qiodevice.h>
46 #include <QtNetwork/qabstractsocket.h>
47 
49 
51 
52 QT_MODULE(Network)
53 
54 #ifndef QT_NO_LOCALSOCKET
55 
57 
59 {
60  Q_OBJECT
62 
63 public:
65  {
66  ConnectionRefusedError = QAbstractSocket::ConnectionRefusedError,
68  ServerNotFoundError = QAbstractSocket::HostNotFoundError,
70  SocketResourceError = QAbstractSocket::SocketResourceError,
72  DatagramTooLargeError = QAbstractSocket::DatagramTooLargeError,
73  ConnectionError = QAbstractSocket::NetworkError,
74  UnsupportedSocketOperationError = QAbstractSocket::UnsupportedSocketOperationError,
76  };
77 
79  {
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:
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>
150 #endif
151 
152 #endif // QT_NO_LOCALSOCKET
153 
155 
157 
158 #endif // QLOCALSOCKET_H
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:62
QIntegerForSizeof< void * >::Unsigned quintptr
Definition: qglobal.h:986
#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
Q_NETWORK_EXPORT QDebug operator<<(QDebug, QLocalSocket::LocalSocketError)
#define QT_MODULE(x)
Definition: qglobal.h:2783
virtual bool waitForReadyRead(int msecs)
Blocks until new data is available for reading and the readyRead() signal has been emitted...
Definition: qiodevice.cpp:1616
virtual void close()
First emits aboutToClose(), then closes the device and sets its OpenMode to NotOpen.
Definition: qiodevice.cpp:590
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
#define error(msg)
virtual qint64 writeData(const char *data, qint64 len)=0
Writes up to maxSize bytes from data to the device.
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
#define Q_PRIVATE_SLOT(d, signature)
Definition: qobjectdefs.h:73
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_SIGNALS
Definition: qobjectdefs.h:72
The QLocalSocket class provides a local socket.
Definition: qlocalsocket.h:58
SocketState
This enum describes the different states in which a socket can be.
virtual qint64 bytesToWrite() const
For buffered devices, this function returns the number of bytes waiting to be written.
Definition: qiodevice.cpp:767
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static QIntfbScreen * connected
const char * name
SocketError
This enum describes the socket errors that can occur.
__int64 qint64
Definition: qglobal.h:942
#define Q_OBJECT
Definition: qobjectdefs.h:157
virtual bool isSequential() const
Returns true if this device is sequential; otherwise returns false.
Definition: qiodevice.cpp:454
virtual qint64 readData(char *data, qint64 maxlen)=0
Reads up to maxSize bytes from the device into data, and returns the number of bytes read or -1 if an...
#define Q_NETWORK_EXPORT
Definition: qglobal.h:1452
virtual qint64 bytesAvailable() const
Returns the number of bytes that are available for reading.
Definition: qiodevice.cpp:752
virtual bool waitForBytesWritten(int msecs)
For buffered devices, this function waits until a payload of buffered written data has been written t...
Definition: qiodevice.cpp:1648
Q_CORE_EXPORT QTextStream & flush(QTextStream &s)
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
virtual bool canReadLine() const
Returns true if a complete line of data can be read from the device; otherwise returns false...
Definition: qiodevice.cpp:1330
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66
#define QT_END_HEADER
Definition: qglobal.h:137
LocalSocketError
The LocalServerError enumeration represents the errors that can occur.
Definition: qlocalsocket.h:64