File indexing completed on 2024-05-12 04:58:51

0001 /**
0002  * SPDX-FileCopyrightText: 2019 Matthijs Tijink <matthijstijink@gmail.com>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 #ifndef MULTIPLEXCHANNEL_H
0008 #define MULTIPLEXCHANNEL_H
0009 
0010 #include <QIODevice>
0011 #include <QSharedPointer>
0012 
0013 class ConnectionMultiplexer;
0014 class MultiplexChannelState;
0015 
0016 /**
0017  * Represents a single channel in a multiplexed connection
0018  *
0019  * @see ConnectionMultiplexer
0020  * @see ConnectionMultiplexer::getChannel
0021  */
0022 class MultiplexChannel : public QIODevice
0023 {
0024     Q_OBJECT
0025 
0026 private:
0027     /**
0028      * You cannot construct a MultiplexChannel yourself, use the ConnectionMultiplexer
0029      */
0030     MultiplexChannel(QSharedPointer<MultiplexChannelState> state);
0031 
0032 public:
0033     ~MultiplexChannel();
0034 
0035     constexpr static int BUFFER_SIZE = 4096;
0036 
0037     bool canReadLine() const override;
0038     bool atEnd() const override;
0039     qint64 bytesAvailable() const override;
0040     qint64 bytesToWrite() const override;
0041 
0042     bool isSequential() const override;
0043 
0044 protected:
0045     qint64 readData(char *data, qint64 maxlen) override;
0046     qint64 writeData(const char *data, qint64 len) override;
0047 
0048 private:
0049     QSharedPointer<MultiplexChannelState> state;
0050 
0051     /**
0052      * Disconnects the channel
0053      */
0054     void disconnect();
0055 
0056     friend class ConnectionMultiplexer;
0057 };
0058 
0059 #endif