Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qlocalsocket.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include <QtNetwork/private/qtnetworkglobal_p.h>
5
6#include "qlocalsocket.h"
7#include "qlocalsocket_p.h"
8
10
359 : QIODevice(*new QLocalSocketPrivate, parent)
360{
361 Q_D(QLocalSocket);
362
363 d->readBufferChunkSize = 0; // force QIODevice unbuffered mode
364 d->init();
365}
366
371{
372 abort();
373#if !defined(Q_OS_WIN) && !defined(QT_LOCALSOCKET_TCP)
374 Q_D(QLocalSocket);
375 d->unixSocket.setParent(nullptr);
376#endif
377}
378
379bool QLocalSocket::open(OpenMode openMode)
380{
382 return isOpen();
383}
384
396void QLocalSocket::connectToServer(const QString &name, OpenMode openMode)
397{
400}
401
411{
412 Q_D(QLocalSocket);
413 if (d->state != UnconnectedState) {
414 qWarning("QLocalSocket::setServerName() called while not in unconnected state");
415 return;
416 }
417 d->serverName = name;
418}
419
428{
429 Q_D(const QLocalSocket);
430 return d->serverName;
431}
432
442QLocalSocket::SocketOptions QLocalSocket::socketOptions() const
443{
444 Q_D(const QLocalSocket);
445 return d->socketOptions;
446}
447
448void QLocalSocket::setSocketOptions(QLocalSocket::SocketOptions option)
449{
450 Q_D(QLocalSocket);
451 if (d->state != UnconnectedState) {
452 qWarning("QLocalSocket::setSocketOptions() called while not in unconnected state");
453 return;
454 }
455 d->socketOptions = option;
456}
457
458QBindable<QLocalSocket::SocketOptions> QLocalSocket::bindableSocketOptions()
459{
460 Q_D(QLocalSocket);
461 return &d->socketOptions;
462}
463
472{
473 Q_D(const QLocalSocket);
474 return d->fullServerName;
475}
476
483{
484 Q_D(const QLocalSocket);
485 return d->state;
486}
487
491{
492 return true;
493}
494
537#ifndef QT_NO_DEBUG_STREAM
539{
540 QDebugStateSaver saver(debug);
541 debug.resetFormat().nospace();
542 switch (error) {
544 debug << "QLocalSocket::ConnectionRefusedError";
545 break;
547 debug << "QLocalSocket::PeerClosedError";
548 break;
550 debug << "QLocalSocket::ServerNotFoundError";
551 break;
553 debug << "QLocalSocket::SocketAccessError";
554 break;
556 debug << "QLocalSocket::SocketResourceError";
557 break;
559 debug << "QLocalSocket::SocketTimeoutError";
560 break;
562 debug << "QLocalSocket::DatagramTooLargeError";
563 break;
565 debug << "QLocalSocket::ConnectionError";
566 break;
568 debug << "QLocalSocket::UnsupportedSocketOperationError";
569 break;
571 debug << "QLocalSocket::UnknownSocketError";
572 break;
574 debug << "QLocalSocket::OperationError";
575 break;
576 default:
577 debug << "QLocalSocket::SocketError(" << int(error) << ')';
578 break;
579 }
580 return debug;
581}
582
584{
585 QDebugStateSaver saver(debug);
586 debug.resetFormat().nospace();
587 switch (state) {
589 debug << "QLocalSocket::UnconnectedState";
590 break;
592 debug << "QLocalSocket::ConnectingState";
593 break;
595 debug << "QLocalSocket::ConnectedState";
596 break;
598 debug << "QLocalSocket::ClosingState";
599 break;
600 default:
601 debug << "QLocalSocket::SocketState(" << int(state) << ')';
602 break;
603 }
604 return debug;
605}
606#endif
607
609
610#include "moc_qlocalsocket.cpp"
\inmodule QtCore
\inmodule QtCore
\inmodule QtCore \reentrant
Definition qiodevice.h:34
bool isOpen() const
Returns true if the device is open; otherwise returns false.
QIODeviceBase::OpenMode openMode() const
Returns the mode in which the device has been opened; i.e.
The QLocalSocket class provides a local socket.
QString fullServerName() const
Returns the server path that the socket is connected to.
void setSocketOptions(SocketOptions option)
SocketOptions socketOptions
the socket options.
QBindable< SocketOptions > bindableSocketOptions()
virtual bool open(OpenMode openMode=ReadWrite) override
Equivalent to connectToServer(OpenMode mode).
virtual bool isSequential() const override
\reimp
LocalSocketState state() const
Returns the state of the socket.
void abort()
Aborts the current connection and resets the socket.
LocalSocketState
This enum describes the different states in which a socket can be.
~QLocalSocket()
Destroys the socket, closing the connection if necessary.
void connectToServer(OpenMode openMode=ReadWrite)
QLocalSocket(QObject *parent=nullptr)
Creates a new local socket.
QString serverName() const
Returns the name of the peer as specified by setServerName(), or an empty QString if setServerName() ...
void setServerName(const QString &name)
LocalSocketError
The LocalServerError enumeration represents the errors that can occur.
@ UnsupportedSocketOperationError
\inmodule QtCore
Definition qobject.h:103
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
else opt state
[0]
Combined button and popup list for selecting options.
DBusConnection const char DBusError * error
QDebug operator<<(QDebug debug, QLocalSocket::LocalSocketError error)
#define qWarning
Definition qlogging.h:166
GLuint name
GLuint GLenum option