61 setSocket(
new QLocalUnixSocket);
64 void QLocalSocketPrivate::setSocket(QLocalUnixSocket* socket)
68 ownsTcpSocket =
false;
73 q->connect(tcpSocket,
SIGNAL(aboutToClose()), q,
SIGNAL(aboutToClose()));
76 q->connect(tcpSocket,
SIGNAL(readyRead()), q,
SIGNAL(readyRead()));
79 q->connect(tcpSocket,
SIGNAL(disconnected()), q,
SIGNAL(disconnected()));
84 q->connect(tcpSocket,
SIGNAL(readChannelFinished()), q,
SIGNAL(readChannelFinished()));
85 tcpSocket->setParent(q);
94 q->setErrorString(errorString);
118 #if defined QLOCALSOCKET_DEBUG 119 qWarning() <<
"QLocalSocket::Unhandled socket state change:" << newState;
123 if (currentState !=
state)
202 q->setErrorString(errorString);
211 q->emit stateChanged(
state);
217 if (
state() == ConnectedState
218 ||
state() == ConnectingState)
221 d->errorString.clear();
222 d->state = ConnectingState;
223 emit stateChanged(
d->state);
226 d->errorOccurred(ServerNotFoundError,
231 d->serverName =
name;
234 d->fullServerName = name;
236 d->fullServerName = prefix + name;
242 d->errorOccurred(ServerNotFoundError,
255 switch (socketState) {
256 case ConnectingState:
265 case UnconnectedState:
270 d->state = socketState;
277 if (childTcpSocket && childTcpSocket->
socketDescriptor() == socketDescriptor) {
278 d->setSocket( static_cast<QLocalUnixSocket*>(childTcpSocket) );
286 return d->tcpSocket->setSocketDescriptor(socketDescriptor,
287 newSocketState, openMode);
293 return d->tcpSocket->socketDescriptor();
299 return d->tcpSocket->readData(data, c);
305 return d->tcpSocket->writeData(data, c);
311 d->tcpSocket->abort();
323 return d->tcpSocket->bytesToWrite();
335 d->tcpSocket->close();
336 d->serverName.clear();
337 d->fullServerName.clear();
344 return d->tcpSocket->waitForBytesWritten(msecs);
350 return d->tcpSocket->flush();
356 d->tcpSocket->disconnectFromHost();
362 switch (
d->tcpSocket->error()) {
384 #if defined QLOCALSOCKET_DEBUG 385 qWarning() <<
"QLocalSocket error not handled:" <<
d->tcpSocket->error();
389 return UnknownSocketError;
395 return d->tcpSocket->isValid();
401 return d->tcpSocket->readBufferSize();
407 d->tcpSocket->setReadBufferSize(size);
413 if (
state() != ConnectingState)
414 return (
state() == ConnectedState);
416 return d->tcpSocket->waitForConnected(msec);
422 if (
state() == UnconnectedState) {
423 qWarning() <<
"QLocalSocket::waitForDisconnected() is not allowed in UnconnectedState";
426 return (
d->tcpSocket->waitForDisconnected(msecs));
434 return (
d->tcpSocket->waitForReadyRead(msecs));
T qobject_cast(QObject *object)
quintptr socketDescriptor() const
Returns the native socket descriptor of the QLocalSocket object if this is available; otherwise retur...
int socketDescriptor() const
Returns the native socket descriptor of the QAbstractSocket object if this is available; otherwise re...
bool waitForReadyRead(int msecs=30000)
This function blocks until data is available for reading and the QIODevice::readyRead() signal has be...
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Returns the value for setting key.
QIntegerForSizeof< void * >::Unsigned quintptr
#define QT_END_NAMESPACE
This macro expands to.
LocalSocketState
This enum describes the different states in which a socket can be.
bool waitForConnected(int msecs=30000)
Waits until the socket is connected, up to msecs milliseconds.
QIODevice::OpenMode openMode
virtual void close()
First emits aboutToClose(), then closes the device and sets its OpenMode to NotOpen.
The QSettings class provides persistent platform-independent application settings.
QLocalSocket::LocalSocketState state
virtual void close()
Reimplemented Function
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool waitForDisconnected(int msecs=30000)
Waits until the socket has disconnected, up to msecs milliseconds.
The QString class provides a Unicode character string.
virtual qint64 writeData(const char *, qint64)
Reimplemented Function
The QObject class is the base class of all Qt objects.
QLocalSocket::LocalSocketError error
The QLocalSocket class provides a local socket.
qint64 readBufferSize() const
Returns the size of the internal read buffer.
SocketState
This enum describes the different states in which a socket can be.
#define QT_BEGIN_NAMESPACE
This macro expands to.
static QIntfbScreen * connected
virtual qint64 readData(char *, qint64)
Reimplemented Function
void setReadBufferSize(qint64 size)
Sets the size of QLocalSocket's internal read buffer to be size bytes.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
SocketError
This enum describes the socket errors that can occur.
Q_CORE_EXPORT void qWarning(const char *,...)
bool flush()
This function writes as much as possible from the internal write buffer to the socket, without blocking.
The QLocalServer class provides a local socket based server.
static const char * data(const QByteArray &arr)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
void connectToServer(const QString &name, OpenMode openMode=ReadWrite)
Attempts to make a connection to name.
The QTcpSocket class provides a TCP socket.
LocalSocketError error() const
Returns the type of error that last occurred.
virtual qint64 bytesToWrite() const
Reimplemented Function
bool isValid() const
Returns true if the socket is valid and ready for use; otherwise returns false.
virtual bool canReadLine() const
Reimplemented Function
void abort()
Aborts the current connection and resets the socket.
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
void clear()
Clears the contents of the string and makes it empty.
bool waitForBytesWritten(int msecs=30000)
Reimplemented Function
uint toUInt(bool *ok=0) const
Returns the variant as an unsigned int if the variant has type() UInt , Bool , ByteArray ...
virtual qint64 bytesAvailable() const
Returns the number of bytes that are available for reading.
virtual qint64 bytesAvailable() const
Reimplemented Function
const QObjectList & children() const
Returns a list of child objects.
virtual bool open(OpenMode mode)
Opens the device and sets its OpenMode to mode.
virtual bool canReadLine() const
Returns true if a complete line of data can be read from the device; otherwise returns false...
LocalSocketError
The LocalServerError enumeration represents the errors that can occur.
bool setSocketDescriptor(quintptr socketDescriptor, LocalSocketState socketState=ConnectedState, OpenMode openMode=ReadWrite)
void disconnectFromServer()
Attempts to close the socket.