1// Copyright (C) 2017-2015 Ford Motor Company
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QCONNECTIONTCPIPBACKEND_P_H
5#define QCONNECTIONTCPIPBACKEND_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "qconnectionfactories_p.h"
19
20#include <QtNetwork/qtcpserver.h>
21#include <QtNetwork/qtcpsocket.h>
22
23QT_BEGIN_NAMESPACE
24
25class TcpClientIo final : public QtROClientIoDevice
26{
27 Q_OBJECT
28
29public:
30 explicit TcpClientIo(QObject *parent = nullptr);
31 ~TcpClientIo() override;
32
33 QIODevice *connection() const override;
34 void connectToServer() override;
35 bool isOpen() const override;
36
37public Q_SLOTS:
38 void onError(QAbstractSocket::SocketError error);
39 void onStateChanged(QAbstractSocket::SocketState state);
40
41protected:
42 void doClose() override;
43 void doDisconnectFromServer() override;
44
45private:
46 QTcpSocket *m_socket;
47};
48
49class TcpServerIo final : public QtROServerIoDevice
50{
51 Q_OBJECT
52public:
53 explicit TcpServerIo(QTcpSocket *conn, QObject *parent = nullptr);
54
55 QIODevice *connection() const override;
56protected:
57 void doClose() override;
58
59private:
60 QTcpSocket *m_connection;
61};
62
63class TcpServerImpl final : public QConnectionAbstractServer
64{
65 Q_OBJECT
66 Q_DISABLE_COPY(TcpServerImpl)
67
68public:
69 explicit TcpServerImpl(QObject *parent);
70 ~TcpServerImpl() override;
71
72 bool hasPendingConnections() const override;
73 QtROServerIoDevice *configureNewConnection() override;
74 QUrl address() const override;
75 bool listen(const QUrl &address) override;
76 QAbstractSocket::SocketError serverError() const override;
77 void close() override;
78
79private:
80 QTcpServer m_server;
81 QUrl m_originalUrl; // necessary because of a QHostAddress bug
82};
83
84QT_END_NAMESPACE
85#endif // QCONNECTIONTCPIPBACKEND_P_H
86

source code of qtremoteobjects/src/remoteobjects/qconnection_tcpip_backend_p.h