2 * bytestream.h - base class for bytestreams
3 * Copyright (C) 2003 Justin Karneges
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef CS_BYTESTREAM_H
22 #define CS_BYTESTREAM_H
24 #include <QtCore/QObject>
25 #include <QtNetwork/QAbstractSocket>
30 class ByteStream
: public QObject
34 enum Error
{ ErrRead
, ErrWrite
, ErrCustom
= 10 };
35 ByteStream(QObject
*parent
=0);
36 virtual ~ByteStream()=0;
38 virtual bool isOpen() const;
40 virtual void write(const QByteArray
&);
41 virtual QByteArray
read(int bytes
=0);
42 virtual int bytesAvailable() const;
43 virtual int bytesToWrite() const;
45 static void appendArray(QByteArray
*a
, const QByteArray
&b
);
46 static QByteArray
takeArray(QByteArray
*from
, int size
=0, bool del
=true);
49 void connectionClosed();
50 void delayedCloseFinished();
52 void bytesWritten(int);
53 void error(QAbstractSocket::SocketError
);
56 void clearReadBuffer();
57 void clearWriteBuffer();
58 void appendRead(const QByteArray
&);
59 void appendWrite(const QByteArray
&);
60 QByteArray
takeRead(int size
=0, bool del
=true);
61 QByteArray
takeWrite(int size
=0, bool del
=true);
62 QByteArray
& readBuf();
63 QByteArray
& writeBuf();
64 virtual int tryWrite();