1 /***************************************************************************
3 * Copyright (C) 2006 David Brodsky *
5 * This library is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU Library General Public *
7 * License as published by the Free Software Foundation and appearing *
8 * in the file LICENSE.LGPL included in the packaging of this file. *
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 * Library General Public License for more details. *
15 ***************************************************************************/
17 #ifndef _tairon_net_limit_reader_h
18 #define _tairon_net_limit_reader_h
20 #include <tairon/core/signals.h>
31 /** \brief This class provides base class for readers.
33 * Reader is an object that reads data from a socket and limits incoming
34 * bandwidth according to its Limiter.
36 * This class must not be used directly because the internal buffer must be set
42 /** Creates a Reader object.
44 * \param s Socket from which the Reader is reading.
45 * \param l Limiter used for limiting bandwidth.
47 Reader(Socket
*s
, Limiter
*l
);
49 /** Destroys the object.
53 /** Returns pointer to the internal buffer.
55 const char *getBuffer() {
59 /** Reads data from the socket.
63 /** Sets offset to the internal buffer to zero. It is useful for
64 * reusing this reader.
69 /** Emitted when the internal buffer is full.
71 Tairon::Core::Signal1
<void, Reader
*> bufferFullSignal
;
73 /** Emitted when there are new data in the buffer.
75 * The receiver gets pointer to this Reader as the first parameter and
76 * number of bytes read as the second one.
78 Tairon::Core::Signal2
<void, Reader
*, size_t> dataReadSignal
;
80 /** This signal is emitted when a socket error occurs. It could also
81 * mean that the connection has been closed. The socket is already
82 * closed when the signal is emitted.
84 Tairon::Core::Signal2
<void, Reader
*, Socket
*> errorSignal
;
87 /** Buffer for storing incoming data.
91 /** Size of the buffer;
95 /** Limiter used for limiting bandwidth.
99 /** Offset from the beginning of the buffer.
103 /** Functor for calling read method.
105 Tairon::Core::Functor0
<void> *readFunctor
;
107 /** Socket from which the Reader is reading.
114 }; // namespace Tairon
118 // vim: ai sw=4 ts=4 noet fdm=marker