Changeset 16:d70b0c40fe4a in xplcommon


Ignore:
Timestamp:
12/29/12 10:24:28 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Renamed BufferedWaitable to BufferedStream

Files:
8 edited
3 moved

Legend:

Unmodified
Added
Removed
  • TODO

    r14 r16  
    1 - POSIX: the buffered waitable should be renamed BufferedStream (or something like that), and made public
  • src/xplcommon/posix/BufferedStream.cc

    r14 r16  
    3030//------------------------------------------------------------------------------
    3131
    32 #include "BufferedWaitable.h"
     32#include "BufferedStream.h"
    3333
    3434#include "ReadingBuffer.h"
     
    4040//------------------------------------------------------------------------------
    4141
    42 using xplcommon::posix::BufferedWaitable;
     42using xplcommon::posix::BufferedStream;
    4343
    4444//------------------------------------------------------------------------------
    4545
    46 BufferedWaitable::BufferedWaitable(Waiter* waiter, int fd,
     46BufferedStream::BufferedStream(Waiter* waiter, int fd,
    4747                                   size_t readingCapacity,
    4848                                   size_t writingCapacity,
     
    5858//------------------------------------------------------------------------------
    5959
    60 BufferedWaitable::~BufferedWaitable()
     60BufferedStream::~BufferedStream()
    6161{
    6262    delete writingBuffer;
     
    6666//------------------------------------------------------------------------------
    6767
    68 ssize_t BufferedWaitable::read(void* dest, size_t length)
     68ssize_t BufferedStream::read(void* dest, size_t length)
    6969{
    7070    ssize_t result = ::read(fd, dest, length);
     
    7777//------------------------------------------------------------------------------
    7878
    79 ssize_t BufferedWaitable::write(const void* src, size_t length)
     79ssize_t BufferedStream::write(const void* src, size_t length)
    8080{
    8181    ssize_t result = ::write(fd, src, length);
     
    8888//------------------------------------------------------------------------------
    8989
    90 bool BufferedWaitable::isReady()
     90bool BufferedStream::isReady()
    9191{
    9292    return false;
     
    9595//------------------------------------------------------------------------------
    9696
    97 void BufferedWaitable::handleEvents(short ev)
     97void BufferedStream::handleEvents(short ev)
    9898{
    9999    if ((ev&POLLIN)==POLLIN && readingBuffer!=0) {
  • src/xplcommon/posix/BufferedStream.h

    r14 r16  
    2828// either expressed or implied, of the FreeBSD Project.
    2929
    30 #ifndef XPLCOMMON_POSIX_BUFFEREDWAITABLE_H
    31 #define XPLCOMMON_POSIX_BUFFEREDWAITABLE_H
     30#ifndef XPLCOMMON_POSIX_BUFFEREDSTREAM_H
     31#define XPLCOMMON_POSIX_BUFFEREDSTREAM_H
    3232//------------------------------------------------------------------------------
    3333
     
    5151 * it.
    5252 */
    53 class BufferedWaitable : public Waitable
     53class BufferedStream : public Waitable
    5454{
    5555public:
     
    7878     * the corresponding buffer will not be created.
    7979     */
    80     BufferedWaitable(Waiter* waiter = 0, int fd = -1,
     80    BufferedStream(Waiter* waiter = 0, int fd = -1,
    8181                     size_t readingCapacity = DEFAULT_CAPACITY,
    8282                     size_t writingCapacity = DEFAULT_CAPACITY,
     
    8787     * Destroy the buffered waitable.
    8888     */
    89     virtual ~BufferedWaitable();
     89    virtual ~BufferedStream();
    9090
    9191    /**
     
    145145//------------------------------------------------------------------------------
    146146
    147 inline ReadingBuffer& BufferedWaitable::getReadingBuffer()
     147inline ReadingBuffer& BufferedStream::getReadingBuffer()
    148148{
    149149    return *readingBuffer;
     
    152152//------------------------------------------------------------------------------
    153153
    154 inline WritingBuffer& BufferedWaitable::getWritingBuffer()
     154inline WritingBuffer& BufferedStream::getWritingBuffer()
    155155{
    156156    return *writingBuffer;
     
    162162
    163163//------------------------------------------------------------------------------
    164 #endif // XPLCOMMON_POSIX_BUFFEREDWAITABLE_H
     164#endif // XPLCOMMON_POSIX_BUFFEREDSTREAM_H
    165165
    166166// Local Variables:
  • src/xplcommon/posix/ClientSocket.cc

    r14 r16  
    6969    }
    7070
    71     BufferedWaitable::handleEvents(events);
     71    BufferedStream::handleEvents(events);
    7272}
    7373
  • src/xplcommon/posix/Makefile.am

    r15 r16  
    88        ReadingBuffer.cc        \
    99        WritingBuffer.cc        \
    10         BufferedWaitable.cc     \
     10        BufferedStream.cc       \
    1111        Acceptor.cc             \
    1212        ServerSocket.cc         \
     
    2323        Waiter.h                \
    2424        WaitableEvent.h         \
    25         WaitableBuffer.h        \
     25        StreamBuffer.h          \
    2626        ReadingBuffer.h         \
    2727        WritingBuffer.h         \
    28         BufferedWaitable.h      \
     28        BufferedStream.h        \
    2929        Acceptor.h              \
    3030        ServerSocket.h          \
  • src/xplcommon/posix/ReadingBuffer.cc

    r14 r16  
    3232#include "ReadingBuffer.h"
    3333
    34 #include "BufferedWaitable.h"
     34#include "BufferedStream.h"
    3535
    3636#include <poll.h>
     
    4747
    4848    if (getLength()>0) {
    49         waitable.events &= ~POLLIN;
     49        stream.events &= ~POLLIN;
    5050        return true;
    5151    }
    5252
    53     ssize_t result = waitable.read(getData(), getCapacity());
     53    ssize_t result = stream.read(getData(), getCapacity());
    5454    if (result<0) {
    55         if (waitable.failed()) {
    56             waitable.events &= ~POLLIN;
     55        if (stream.failed()) {
     56            stream.events &= ~POLLIN;
    5757        } else {
    58             waitable.events |= POLLIN;
     58            stream.events |= POLLIN;
    5959        }
    6060    } else {
    61         waitable.events &= ~POLLIN;
     61        stream.events &= ~POLLIN;
    6262        addLength(result);
    6363    }
  • src/xplcommon/posix/ReadingBuffer.h

    r6 r16  
    3232//------------------------------------------------------------------------------
    3333
    34 #include "WaitableBuffer.h"
     34#include "StreamBuffer.h"
    3535
    3636//------------------------------------------------------------------------------
     
    4747 * amount of data read is 0, that indicates and end-of-file condition.
    4848 */
    49 class ReadingBuffer : public WaitableBuffer
     49class ReadingBuffer : public StreamBuffer
    5050{
    5151protected:
     
    5353     * Construct the buffer.
    5454     */
    55     ReadingBuffer(size_t capacity, BufferedWaitable* waitable);
     55    ReadingBuffer(size_t capacity, BufferedStream* stream);
    5656
    5757public:
    5858    /**
    59      * Read into the buffer using the buffered waitable if possible.
     59     * Read into the buffer using the buffered stream if possible.
    6060     *
    6161     * If the buffer contains data, this function returns immediately
     
    6767     * end-of-file or end-of-connection condition.
    6868     *
    69      * If the reading operation would block, the waitable is set up so
     69     * If the reading operation would block, the stream is set up so
    7070     * that it would read, and failure is returned.
    7171     *
     
    7676    bool read();
    7777
    78     friend class BufferedWaitable;
     78    friend class BufferedStream;
    7979};
    8080
     
    8383//------------------------------------------------------------------------------
    8484
    85 inline ReadingBuffer::ReadingBuffer(size_t capacity,
    86                                     BufferedWaitable* waitable) :
    87     WaitableBuffer(capacity, waitable)
     85inline ReadingBuffer::ReadingBuffer(size_t capacity, BufferedStream* stream) :
     86    StreamBuffer(capacity, stream)
    8887{
    8988}
  • src/xplcommon/posix/Socket.h

    r14 r16  
    3232//------------------------------------------------------------------------------
    3333
    34 #include "BufferedWaitable.h"
     34#include "BufferedStream.h"
    3535
    3636//------------------------------------------------------------------------------
     
    4747 * A buffered, waitable socket implementation.
    4848 */
    49 class Socket : public BufferedWaitable
     49class Socket : public BufferedStream
    5050{
    5151private:
     
    8585inline Socket::Socket(int domain, int type, Waiter* waiter, int protocol,
    8686                      size_t readingCapacity, size_t writingCapacity) :
    87     BufferedWaitable(waiter, socket(domain, type, protocol),
     87    BufferedStream(waiter, socket(domain, type, protocol),
    8888                     readingCapacity, writingCapacity)
    8989{
     
    9595inline Socket::Socket(int fd, Waiter* waiter,
    9696                      size_t readingCapacity, size_t writingCapacity) :
    97     BufferedWaitable(waiter, fd, readingCapacity, writingCapacity)
     97    BufferedStream(waiter, fd, readingCapacity, writingCapacity)
    9898{
    9999}
  • src/xplcommon/posix/StreamBuffer.h

    r14 r16  
    2828// either expressed or implied, of the FreeBSD Project.
    2929
    30 #ifndef XPLCOMMON_POSIX_WAITABLEBUFFER_H
    31 #define XPLCOMMON_POSIX_WAITABLEBUFFER_H
     30#ifndef XPLCOMMON_POSIX_STREAMBUFFER_H
     31#define XPLCOMMON_POSIX_STREAMBUFFER_H
    3232//------------------------------------------------------------------------------
    3333
     
    3535#include "../Failable.h"
    3636
    37 #include "BufferedWaitable.h"
     37#include "BufferedStream.h"
    3838
    3939//------------------------------------------------------------------------------
     
    4444
    4545/**
    46  * Base class for buffers used by a BufferedWaitable.
     46 * Base class for buffers used by a BufferedStream.
    4747 */
    48 class WaitableBuffer : public ::xplcommon::Buffer,
    49                        public ::xplcommon::FailableReference<WaitableBuffer>
     48class StreamBuffer : public ::xplcommon::Buffer,
     49                     public ::xplcommon::FailableReference<StreamBuffer>
    5050{
    5151protected:
    5252    /**
    53      * Our waitable.
     53     * Our buffered stream.
    5454     */
    55     BufferedWaitable& waitable;
     55    BufferedStream& stream;
    5656
    5757protected:
     
    5959     * Construct the buffer with the given waitable.
    6060     */
    61     WaitableBuffer(size_t capacity, BufferedWaitable* waitable);
     61    StreamBuffer(size_t capacity, BufferedStream* stream);
    6262
    6363private:
     
    7272    ::xplcommon::Failable& getFailable();
    7373
    74     friend class FailableReference<WaitableBuffer>;
     74    friend class FailableReference<StreamBuffer>;
    7575};
    7676
     
    7979//------------------------------------------------------------------------------
    8080
    81 inline WaitableBuffer::WaitableBuffer(size_t capacity,
    82                                       BufferedWaitable* waitable) :
     81inline StreamBuffer::StreamBuffer(size_t capacity, BufferedStream* stream) :
    8382    Buffer(capacity),
    84     waitable(*waitable)
     83    stream(*stream)
    8584{
    8685}
     
    8887//------------------------------------------------------------------------------
    8988
    90 inline const ::xplcommon::Failable& WaitableBuffer::getFailable() const
     89inline const ::xplcommon::Failable& StreamBuffer::getFailable() const
    9190{
    92     return waitable;
     91    return stream;
    9392}
    9493
    9594//------------------------------------------------------------------------------
    9695
    97 inline ::xplcommon::Failable& WaitableBuffer::getFailable()
     96inline ::xplcommon::Failable& StreamBuffer::getFailable()
    9897{
    99     return waitable;
     98    return stream;
    10099}
    101100
     
    105104
    106105//------------------------------------------------------------------------------
    107 #endif // XPLCOMMON_POSIX_WAITABLEBUFFER_H
     106#endif // XPLCOMMON_POSIX_STREAMBUFFER_H
    108107
    109108// Local Variables:
  • src/xplcommon/posix/WritingBuffer.cc

    r14 r16  
    3232#include "WritingBuffer.h"
    3333
    34 #include "BufferedWaitable.h"
     34#include "BufferedStream.h"
    3535
    3636#include <poll.h>
     
    4646    Buffer::reset();
    4747    offset = 0;
    48     waitable.events &= ~POLLOUT;
     48    stream.events &= ~POLLOUT;
    4949}
    5050
     
    6262    size_t toWrite = getLength() - offset;
    6363
    64     ssize_t result = waitable.write(getData() + offset, toWrite);
     64    ssize_t result = stream.write(getData() + offset, toWrite);
    6565    if (result<static_cast<ssize_t>(toWrite)) {
    66         if (result<0 && waitable.failed()) {
    67             waitable.events &= ~POLLOUT;
     66        if (result<0 && stream.failed()) {
     67            stream.events &= ~POLLOUT;
    6868        } else {
    69             waitable.events |= POLLOUT;
     69            stream.events |= POLLOUT;
    7070            if (result>0) offset += result;
    7171        }
  • src/xplcommon/posix/WritingBuffer.h

    r6 r16  
    3232//------------------------------------------------------------------------------
    3333
    34 #include "WaitableBuffer.h"
     34#include "StreamBuffer.h"
    3535
    3636//------------------------------------------------------------------------------
     
    4747 * has been written. In that case the buffer is automatically emptied.
    4848 */
    49 class WritingBuffer : public WaitableBuffer
     49class WritingBuffer : public StreamBuffer
    5050{
    5151private:
     
    5959     * Construct the buffer.
    6060     */
    61     WritingBuffer(size_t capacity, BufferedWaitable* waitable);
     61    WritingBuffer(size_t capacity, BufferedStream* stream);
    6262
    6363public:
     
    6969    /**
    7070     * Write the contents of the buffer using the associated buffered
    71      * waitable.
     71     * stream.
    7272     *
    7373     * If the buffer is empty, the function returns indicating
     
    7979     * If not everything can be written and the write operation
    8080     * indicates that it would block, this function returns failure
    81      * after the waitable has been set up  to handle the corresponding
     81     * after the stream has been set up  to handle the corresponding
    8282     * poll events.
    8383     *
     
    8888    bool write();
    8989
    90     friend class BufferedWaitable;
     90    friend class BufferedStream;
    9191};
    9292
     
    9595//------------------------------------------------------------------------------
    9696
    97 inline WritingBuffer::WritingBuffer(size_t capacity,
    98                                     BufferedWaitable* waitable):
    99     WaitableBuffer(capacity, waitable),
     97inline WritingBuffer::WritingBuffer(size_t capacity, BufferedStream* stream):
     98    StreamBuffer(capacity, stream),
    10099    offset(0)
    101100{
Note: See TracChangeset for help on using the changeset viewer.