• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDECore

  • kdecore
  • network
k3socketbuffer_p.h
Go to the documentation of this file.
1/* -*- C++ -*-
2 * Copyright (C) 2003,2005 Thiago Macieira <thiago@kde.org>
3 *
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25#ifndef KSOCKETBUFFER_P_H
26#define KSOCKETBUFFER_P_H
27
28#include <QMutex>
29#include <QByteArray>
30#include <QList>
31
32namespace KNetwork {
33
34class KActiveSocketBase;
35
36 namespace Internal {
37
48class KSocketBuffer
49{
50public:
56 KSocketBuffer(qint64 size = -1);
57
61 KSocketBuffer(const KSocketBuffer& other);
62
66 ~KSocketBuffer();
67
71 KSocketBuffer& operator=(const KSocketBuffer& other);
72
76 bool canReadLine() const;
77
81 qint64 readLine(char *data, qint64 maxSize);
82
89 qint64 length() const;
90
94 inline bool isEmpty() const
95 { return length() == 0; }
96
103 qint64 size() const;
104
112 bool setSize(qint64 size);
113
117 inline bool isFull() const
118 { return size() != -1 && size() == length(); }
119
127 qint64 feedBuffer(const char *data, qint64 len);
128
132 void clear();
133
142 qint64 consumeBuffer(char *data, qint64 maxlen, bool discard = true);
143
152 qint64 sendTo(KActiveSocketBase* device, qint64 len = -1);
153
163 qint64 receiveFrom(KActiveSocketBase* device, qint64 len = -1);
164
165protected:
166 mutable QMutex m_mutex;
167 QList<QByteArray> m_list;
168 qint64 m_offset;
169
170 qint64 m_size;
171 mutable qint64 m_length;
172};
173
174} } // namespace KNetwork::Internal
175
176#endif
KNetwork::Internal::KSocketBuffer
generic socket buffering code
Definition: k3socketbuffer_p.h:49
KNetwork::Internal::KSocketBuffer::m_offset
qint64 m_offset
offset of the start of data in the first element
Definition: k3socketbuffer_p.h:168
KNetwork::Internal::KSocketBuffer::feedBuffer
qint64 feedBuffer(const char *data, qint64 len)
Adds data to the end of the buffer.
Definition: k3socketbuffer.cpp:150
KNetwork::Internal::KSocketBuffer::clear
void clear()
Clears the buffer.
Definition: k3socketbuffer.cpp:220
KNetwork::Internal::KSocketBuffer::m_length
qint64 m_length
Definition: k3socketbuffer_p.h:171
KNetwork::Internal::KSocketBuffer::m_list
QList< QByteArray > m_list
Definition: k3socketbuffer_p.h:167
KNetwork::Internal::KSocketBuffer::operator=
KSocketBuffer & operator=(const KSocketBuffer &other)
Assignment operator.
Definition: k3socketbuffer.cpp:56
KNetwork::Internal::KSocketBuffer::length
qint64 length() const
Returns the number of bytes in the buffer.
Definition: k3socketbuffer.cpp:123
KNetwork::Internal::KSocketBuffer::canReadLine
bool canReadLine() const
Returns true if a line can be read from the buffer.
Definition: k3socketbuffer.cpp:69
KNetwork::Internal::KSocketBuffer::readLine
qint64 readLine(char *data, qint64 maxSize)
Reads a line from the buffer and discard it from the buffer.
Definition: k3socketbuffer.cpp:88
KNetwork::Internal::KSocketBuffer::consumeBuffer
qint64 consumeBuffer(char *data, qint64 maxlen, bool discard=true)
Consumes data from the beginning of the buffer.
Definition: k3socketbuffer.cpp:170
KNetwork::Internal::KSocketBuffer::size
qint64 size() const
Retrieves the buffer size.
Definition: k3socketbuffer.cpp:128
KNetwork::Internal::KSocketBuffer::m_size
qint64 m_size
the maximum length of the buffer
Definition: k3socketbuffer_p.h:170
KNetwork::Internal::KSocketBuffer::setSize
bool setSize(qint64 size)
Sets the size of the buffer, if allowed.
Definition: k3socketbuffer.cpp:133
KNetwork::Internal::KSocketBuffer::m_mutex
QMutex m_mutex
Definition: k3socketbuffer_p.h:166
KNetwork::Internal::KSocketBuffer::receiveFrom
qint64 receiveFrom(KActiveSocketBase *device, qint64 len=-1)
Tries to receive len bytes of data from the I/O device.
Definition: k3socketbuffer.cpp:293
KNetwork::Internal::KSocketBuffer::isFull
bool isFull() const
Returns true if the buffer is full (i.e., cannot receive more data)
Definition: k3socketbuffer_p.h:117
KNetwork::Internal::KSocketBuffer::isEmpty
bool isEmpty() const
Returns true if the buffer is empty of data.
Definition: k3socketbuffer_p.h:94
KNetwork::Internal::KSocketBuffer::~KSocketBuffer
~KSocketBuffer()
Virtual destructor.
Definition: k3socketbuffer.cpp:51
KNetwork::Internal::KSocketBuffer::sendTo
qint64 sendTo(KActiveSocketBase *device, qint64 len=-1)
Sends at most len bytes of data to the I/O Device.
Definition: k3socketbuffer.cpp:228
KNetwork::KActiveSocketBase
Abstract class for active sockets.
Definition: k3socketbase.h:462
QList
Definition: kaboutdata.h:33
qint64
KNetwork
A namespace to store all networking-related (socket) classes.
Definition: k3bufferedsocket.h:35
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal