KDECore
k3socketbuffer_p.h
Go to the documentation of this file.
00001 /* -*- C++ -*- 00002 * Copyright (C) 2003,2005 Thiago Macieira <thiago@kde.org> 00003 * 00004 * 00005 * Permission is hereby granted, free of charge, to any person obtaining 00006 * a copy of this software and associated documentation files (the 00007 * "Software"), to deal in the Software without restriction, including 00008 * without limitation the rights to use, copy, modify, merge, publish, 00009 * distribute, sublicense, and/or sell copies of the Software, and to 00010 * permit persons to whom the Software is furnished to do so, subject to 00011 * the following conditions: 00012 * 00013 * The above copyright notice and this permission notice shall be included 00014 * in all copies or substantial portions of the Software. 00015 * 00016 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00017 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00018 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00019 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 00020 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 00021 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 00022 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00023 */ 00024 00025 #ifndef KSOCKETBUFFER_P_H 00026 #define KSOCKETBUFFER_P_H 00027 00028 #include <QMutex> 00029 #include <QByteArray> 00030 #include <QList> 00031 00032 namespace KNetwork { 00033 00034 class KActiveSocketBase; 00035 00036 namespace Internal { 00037 00048 class KSocketBuffer 00049 { 00050 public: 00056 KSocketBuffer(qint64 size = -1); 00057 00061 KSocketBuffer(const KSocketBuffer& other); 00062 00066 ~KSocketBuffer(); 00067 00071 KSocketBuffer& operator=(const KSocketBuffer& other); 00072 00076 bool canReadLine() const; 00077 00081 qint64 readLine(char *data, qint64 maxSize); 00082 00089 qint64 length() const; 00090 00094 inline bool isEmpty() const 00095 { return length() == 0; } 00096 00103 qint64 size() const; 00104 00112 bool setSize(qint64 size); 00113 00117 inline bool isFull() const 00118 { return size() != -1 && size() == length(); } 00119 00127 qint64 feedBuffer(const char *data, qint64 len); 00128 00132 void clear(); 00133 00142 qint64 consumeBuffer(char *data, qint64 maxlen, bool discard = true); 00143 00152 qint64 sendTo(KActiveSocketBase* device, qint64 len = -1); 00153 00163 qint64 receiveFrom(KActiveSocketBase* device, qint64 len = -1); 00164 00165 protected: 00166 mutable QMutex m_mutex; 00167 QList<QByteArray> m_list; 00168 qint64 m_offset; 00169 00170 qint64 m_size; 00171 mutable qint64 m_length; 00172 }; 00173 00174 } } // namespace KNetwork::Internal 00175 00176 #endif
KDE 4.6 API Reference