28 #include <config-network.h>
33 #include <QMutableListIterator>
37 using namespace KNetwork;
38 using namespace KNetwork::Internal;
40 KSocketBuffer::KSocketBuffer(
qint64 size)
41 : m_mutex(QMutex::Recursive), m_offset(0), m_size(size), m_length(0)
46 : m_mutex(QMutex::Recursive)
59 QMutexLocker locker2(&other.
m_mutex);
76 for (
int i = 0; i <
m_list.size(); ++i)
78 if (
m_list.at(i).indexOf(
'\n', offset) != -1)
80 if (
m_list.at(i).indexOf(
'\r', offset) != -1)
100 for (
int i = 0; i <
m_list.size(); ++i)
102 int posnl =
m_list.at(i).indexOf(
'\n', offset);
106 newline +=
m_list.at(i).size();
117 if (bytesToRead > maxSize)
118 bytesToRead = maxSize;
152 if (data == 0L || len == 0)
163 QByteArray a(data, len);
175 QMutableListIterator<QByteArray> it(
m_list);
180 while (it.hasNext() && maxlen)
182 QByteArray& item = it.next();
184 qint64 to_copy = item.size() - offset;
185 if (to_copy > maxlen)
190 memcpy(destbuffer + copied, item.data() + offset, to_copy);
194 if (item.size() - offset > to_copy)
235 QMutableListIterator<QByteArray> it(
m_list);
240 while (it.hasNext() && (len || len == -1))
248 if (len != -1 && len < bufsize)
250 QByteArray buf(bufsize,
'\0');
253 while (it.hasNext() && count + (it.peekNext().size() - offset) <= bufsize)
255 QByteArray& item = it.next();
256 memcpy(buf.data() + count, item.data() + offset, item.size() - offset);
257 count += item.size() - offset;
262 if (count < bufsize && it.hasNext())
266 QByteArray& item = it.next();
267 memcpy(buf.data() + count, item.data() + offset, bufsize - count);
268 offset += bufsize - count;
301 len = dev->bytesAvailable();
313 QByteArray a(len,
'\0');
314 len = dev->
read(a.data(), len);