| 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 | // Qt-Security score:significant reason:default |
| 4 | |
| 5 | //#define QTCPSOCKET_DEBUG |
| 6 | |
| 7 | /*! |
| 8 | \class QTcpSocket |
| 9 | |
| 10 | \brief The QTcpSocket class provides a TCP socket. |
| 11 | |
| 12 | \reentrant |
| 13 | \ingroup network |
| 14 | \inmodule QtNetwork |
| 15 | |
| 16 | TCP (Transmission Control Protocol) is a reliable, |
| 17 | stream-oriented, connection-oriented transport protocol. It is |
| 18 | especially well suited for continuous transmission of data. |
| 19 | |
| 20 | QTcpSocket is a convenience subclass of QAbstractSocket that |
| 21 | allows you to establish a TCP connection and transfer streams of |
| 22 | data. See the QAbstractSocket documentation for details. |
| 23 | |
| 24 | \note TCP sockets cannot be opened in \l QIODeviceBase::Unbuffered mode. |
| 25 | |
| 26 | \sa QTcpServer, QUdpSocket, QNetworkAccessManager, |
| 27 | {Fortune Server}, {Fortune Client}, |
| 28 | {Threaded Fortune Server}, {Blocking Fortune Client}, |
| 29 | {Torrent Example} |
| 30 | */ |
| 31 | |
| 32 | #include "qtcpsocket.h" |
| 33 | #include "qtcpsocket_p.h" |
| 34 | #include "qlist.h" |
| 35 | #include "qhostaddress.h" |
| 36 | |
| 37 | QT_BEGIN_NAMESPACE |
| 38 | |
| 39 | /*! |
| 40 | Creates a QTcpSocket object in state \c UnconnectedState. |
| 41 | |
| 42 | \a parent is passed on to the QObject constructor. |
| 43 | |
| 44 | \sa socketType() |
| 45 | */ |
| 46 | QTcpSocket::QTcpSocket(QObject *parent) |
| 47 | : QAbstractSocket(TcpSocket, *new QTcpSocketPrivate, parent) |
| 48 | { |
| 49 | #if defined(QTCPSOCKET_DEBUG) |
| 50 | qDebug("QTcpSocket::QTcpSocket()" ); |
| 51 | #endif |
| 52 | d_func()->isBuffered = true; |
| 53 | } |
| 54 | |
| 55 | /*! |
| 56 | Destroys the socket, closing the connection if necessary. |
| 57 | |
| 58 | \sa close() |
| 59 | */ |
| 60 | |
| 61 | QTcpSocket::~QTcpSocket() |
| 62 | { |
| 63 | #if defined(QTCPSOCKET_DEBUG) |
| 64 | qDebug("QTcpSocket::~QTcpSocket()" ); |
| 65 | #endif |
| 66 | } |
| 67 | |
| 68 | /*! |
| 69 | \internal |
| 70 | */ |
| 71 | QTcpSocket::QTcpSocket(QTcpSocketPrivate &dd, QObject *parent) |
| 72 | : QAbstractSocket(TcpSocket, dd, parent) |
| 73 | { |
| 74 | d_func()->isBuffered = true; |
| 75 | } |
| 76 | |
| 77 | /*! |
| 78 | \internal |
| 79 | */ |
| 80 | QTcpSocket::QTcpSocket(QAbstractSocket::SocketType socketType, |
| 81 | QTcpSocketPrivate &dd, QObject *parent) |
| 82 | : QAbstractSocket(socketType, dd, parent) |
| 83 | { |
| 84 | } |
| 85 | |
| 86 | QT_END_NAMESPACE |
| 87 | |
| 88 | #include "moc_qtcpsocket.cpp" |
| 89 | |