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 MULTIPLEXCHANNELSTATE_H
0008 #define MULTIPLEXCHANNELSTATE_H
0009 
0010 #include <QByteArray>
0011 #include <QObject>
0012 
0013 class ConnectionMultiplexer;
0014 class MultiplexChannel;
0015 
0016 /**
0017  * Represents a single channel in a multiplexed connection
0018  *
0019  * @internal
0020  * @see ConnectionMultiplexer
0021  */
0022 class MultiplexChannelState : public QObject
0023 {
0024     Q_OBJECT
0025 
0026 private:
0027     MultiplexChannelState();
0028 
0029 public:
0030     constexpr static int BUFFER_SIZE = 4096;
0031 
0032 private:
0033     /**
0034      * The read buffer (already read from underlying connection but not read by the user of the channel)
0035      */
0036     QByteArray read_buffer;
0037     /**
0038      * The write buffer (already written by the user of the channel, but not to the underlying connection yet)
0039      */
0040     QByteArray write_buffer;
0041     /**
0042      * The amount of bytes requested to the other endpoint
0043      */
0044     int requestedReadAmount;
0045     /**
0046      * The amount of bytes the other endpoint requested
0047      */
0048     int freeWriteAmount;
0049     /**
0050      * True if the channel is still connected in the underlying connection
0051      */
0052     bool connected;
0053     /**
0054      * True if the channel needs to be closed after writing the buffer
0055      */
0056     bool close_after_write;
0057     friend class ConnectionMultiplexer;
0058     friend class MultiplexChannel;
0059 
0060 Q_SIGNALS:
0061     /**
0062      * Emitted if there are new bytes available to be written
0063      */
0064     void writeAvailable();
0065     /**
0066      * Emitted if the channel has buffer room for more bytes to be read
0067      */
0068     void readAvailable();
0069     /**
0070      * Emitted if the channel bytes ready for reading
0071      */
0072     void readyRead();
0073     /**
0074      * Emitted if some bytes of the channel have been written
0075      */
0076     void bytesWritten(qint64 amount);
0077     /**
0078      * Emitted if the user requested to close the channel
0079      */
0080     void requestClose();
0081     /**
0082      * Only fired on disconnections
0083      */
0084     void disconnected();
0085 };
0086 
0087 #endif