source: trunk/src/network/socket/qlocalsocket.cpp@ 788

Last change on this file since 788 was 755, checked in by Dmitry A. Kuminov, 15 years ago

network/os2: QLocalServer/QLocalSocket: Make sure the socket path name always starts with "\socket\" (fixes #166) [based on patch by rudi].

File size: 15.3 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtNetwork module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
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** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "qlocalsocket.h"
43#include "qlocalsocket_p.h"
44
45#ifndef QT_NO_LOCALSOCKET
46
47QT_BEGIN_NAMESPACE
48
49/*!
50 \class QLocalSocket
51 \since 4.4
52
53 \brief The QLocalSocket class provides a local socket.
54
55 On Windows this is a named pipe, on Unix and OS/2 this is a local domain
56 socket.
57
58 If an error occurs, socketError() returns the type of error, and
59 errorString() can be called to get a human readable description
60 of what happened.
61
62 Although QLocalSocket is designed for use with an event loop, it's possible
63 to use it without one. In that case, you must use waitForConnected(),
64 waitForReadyRead(), waitForBytesWritten(), and waitForDisconnected()
65 which blocks until the operation is complete or the timeout expires.
66
67 Note that this feature is not supported on versions of Windows earlier than
68 Windows XP.
69
70 \sa QLocalServer
71*/
72
73/*!
74 \fn void QLocalSocket::connectToServer(const QString &name, OpenMode openMode)
75
76 Attempts to make a connection to \a name.
77
78 The socket is opened in the given \a openMode and first enters ConnectingState.
79 It then attempts to connect to the address or addresses returned by the lookup.
80 Finally, if a connection is established, QLocalSocket enters ConnectedState
81 and emits connected().
82
83 At any point, the socket can emit error() to signal that an error occurred.
84
85 See also state(), serverName(), and waitForConnected().
86*/
87
88/*!
89 \fn void QLocalSocket::connected()
90
91 This signal is emitted after connectToServer() has been called and
92 a connection has been successfully established.
93
94 \sa connectToServer(), disconnected()
95*/
96
97/*!
98 \fn bool QLocalSocket::setSocketDescriptor(quintptr socketDescriptor,
99 LocalSocketState socketState, OpenMode openMode)
100
101 Initializes QLocalSocket with the native socket descriptor
102 \a socketDescriptor. Returns true if socketDescriptor is accepted
103 as a valid socket descriptor; otherwise returns false. The socket is
104 opened in the mode specified by \a openMode, and enters the socket state
105 specified by \a socketState.
106
107 \note It is not possible to initialize two local sockets with the same
108 native socket descriptor.
109
110 \sa socketDescriptor(), state(), openMode()
111*/
112
113/*!
114 \fn quintptr QLocalSocket::socketDescriptor() const
115
116 Returns the native socket descriptor of the QLocalSocket object if
117 this is available; otherwise returns -1.
118
119 The socket descriptor is not available when QLocalSocket
120 is in UnconnectedState.
121
122 \sa setSocketDescriptor()
123*/
124
125/*!
126 \fn qint64 QLocalSocket::readData(char *data, qint64 c)
127 \reimp
128*/
129
130/*!
131 \fn qint64 QLocalSocket::writeData(const char *data, qint64 c)
132 \reimp
133*/
134
135/*!
136 \fn void QLocalSocket::abort()
137
138 Aborts the current connection and resets the socket.
139 Unlike disconnectFromServer(), this function immediately closes the socket,
140 clearing any pending data in the write buffer.
141
142 \sa disconnectFromServer(), close()
143*/
144
145/*!
146 \fn qint64 QLocalSocket::bytesAvailable() const
147 \reimp
148*/
149
150/*!
151 \fn qint64 QLocalSocket::bytesToWrite() const
152 \reimp
153*/
154
155/*!
156 \fn bool QLocalSocket::canReadLine() const
157 \reimp
158*/
159
160/*!
161 \fn void QLocalSocket::close()
162 \reimp
163*/
164
165/*!
166 \fn bool QLocalSocket::waitForBytesWritten(int msecs)
167 \reimp
168*/
169
170/*!
171 \fn bool QLocalSocket::flush()
172
173 This function writes as much as possible from the internal write buffer
174 to the socket, without blocking. If any data was written, this function
175 returns true; otherwise false is returned.
176
177 Call this function if you need QLocalSocket to start sending buffered data
178 immediately. The number of bytes successfully written depends on the
179 operating system. In most cases, you do not need to call this function,
180 because QLocalSocket will start sending data automatically once control
181 goes back to the event loop. In the absence of an event loop, call
182 waitForBytesWritten() instead.
183
184 \sa write(), waitForBytesWritten()
185*/
186
187/*!
188 \fn void QLocalSocket::disconnectFromServer()
189
190 Attempts to close the socket. If there is pending data waiting to be
191 written, QLocalSocket will enter ClosingState and wait until all data
192 has been written. Eventually, it will enter UnconnectedState and emit
193 the disconnectedFromServer() signal.
194
195 \sa connectToServer()