Changeset 16:d70b0c40fe4a in xplcommon for src
- Timestamp:
- 12/29/12 10:24:28 (12 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- src/xplcommon/posix
- Files:
-
- 7 edited
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
src/xplcommon/posix/BufferedStream.cc
r14 r16 30 30 //------------------------------------------------------------------------------ 31 31 32 #include "Buffered Waitable.h"32 #include "BufferedStream.h" 33 33 34 34 #include "ReadingBuffer.h" … … 40 40 //------------------------------------------------------------------------------ 41 41 42 using xplcommon::posix::Buffered Waitable;42 using xplcommon::posix::BufferedStream; 43 43 44 44 //------------------------------------------------------------------------------ 45 45 46 Buffered Waitable::BufferedWaitable(Waiter* waiter, int fd,46 BufferedStream::BufferedStream(Waiter* waiter, int fd, 47 47 size_t readingCapacity, 48 48 size_t writingCapacity, … … 58 58 //------------------------------------------------------------------------------ 59 59 60 Buffered Waitable::~BufferedWaitable()60 BufferedStream::~BufferedStream() 61 61 { 62 62 delete writingBuffer; … … 66 66 //------------------------------------------------------------------------------ 67 67 68 ssize_t Buffered Waitable::read(void* dest, size_t length)68 ssize_t BufferedStream::read(void* dest, size_t length) 69 69 { 70 70 ssize_t result = ::read(fd, dest, length); … … 77 77 //------------------------------------------------------------------------------ 78 78 79 ssize_t Buffered Waitable::write(const void* src, size_t length)79 ssize_t BufferedStream::write(const void* src, size_t length) 80 80 { 81 81 ssize_t result = ::write(fd, src, length); … … 88 88 //------------------------------------------------------------------------------ 89 89 90 bool Buffered Waitable::isReady()90 bool BufferedStream::isReady() 91 91 { 92 92 return false; … … 95 95 //------------------------------------------------------------------------------ 96 96 97 void Buffered Waitable::handleEvents(short ev)97 void BufferedStream::handleEvents(short ev) 98 98 { 99 99 if ((ev&POLLIN)==POLLIN && readingBuffer!=0) { -
src/xplcommon/posix/BufferedStream.h
r14 r16 28 28 // either expressed or implied, of the FreeBSD Project. 29 29 30 #ifndef XPLCOMMON_POSIX_BUFFERED WAITABLE_H31 #define XPLCOMMON_POSIX_BUFFERED WAITABLE_H30 #ifndef XPLCOMMON_POSIX_BUFFEREDSTREAM_H 31 #define XPLCOMMON_POSIX_BUFFEREDSTREAM_H 32 32 //------------------------------------------------------------------------------ 33 33 … … 51 51 * it. 52 52 */ 53 class Buffered Waitable: public Waitable53 class BufferedStream : public Waitable 54 54 { 55 55 public: … … 78 78 * the corresponding buffer will not be created. 79 79 */ 80 Buffered Waitable(Waiter* waiter = 0, int fd = -1,80 BufferedStream(Waiter* waiter = 0, int fd = -1, 81 81 size_t readingCapacity = DEFAULT_CAPACITY, 82 82 size_t writingCapacity = DEFAULT_CAPACITY, … … 87 87 * Destroy the buffered waitable. 88 88 */ 89 virtual ~Buffered Waitable();89 virtual ~BufferedStream(); 90 90 91 91 /** … … 145 145 //------------------------------------------------------------------------------ 146 146 147 inline ReadingBuffer& Buffered Waitable::getReadingBuffer()147 inline ReadingBuffer& BufferedStream::getReadingBuffer() 148 148 { 149 149 return *readingBuffer; … … 152 152 //------------------------------------------------------------------------------ 153 153 154 inline WritingBuffer& Buffered Waitable::getWritingBuffer()154 inline WritingBuffer& BufferedStream::getWritingBuffer() 155 155 { 156 156 return *writingBuffer; … … 162 162 163 163 //------------------------------------------------------------------------------ 164 #endif // XPLCOMMON_POSIX_BUFFERED WAITABLE_H164 #endif // XPLCOMMON_POSIX_BUFFEREDSTREAM_H 165 165 166 166 // Local Variables: -
src/xplcommon/posix/ClientSocket.cc
r14 r16 69 69 } 70 70 71 Buffered Waitable::handleEvents(events);71 BufferedStream::handleEvents(events); 72 72 } 73 73 -
src/xplcommon/posix/Makefile.am
r15 r16 8 8 ReadingBuffer.cc \ 9 9 WritingBuffer.cc \ 10 Buffered Waitable.cc \10 BufferedStream.cc \ 11 11 Acceptor.cc \ 12 12 ServerSocket.cc \ … … 23 23 Waiter.h \ 24 24 WaitableEvent.h \ 25 WaitableBuffer.h\25 StreamBuffer.h \ 26 26 ReadingBuffer.h \ 27 27 WritingBuffer.h \ 28 Buffered Waitable.h \28 BufferedStream.h \ 29 29 Acceptor.h \ 30 30 ServerSocket.h \ -
src/xplcommon/posix/ReadingBuffer.cc
r14 r16 32 32 #include "ReadingBuffer.h" 33 33 34 #include "Buffered Waitable.h"34 #include "BufferedStream.h" 35 35 36 36 #include <poll.h> … … 47 47 48 48 if (getLength()>0) { 49 waitable.events &= ~POLLIN;49 stream.events &= ~POLLIN; 50 50 return true; 51 51 } 52 52 53 ssize_t result = waitable.read(getData(), getCapacity());53 ssize_t result = stream.read(getData(), getCapacity()); 54 54 if (result<0) { 55 if ( waitable.failed()) {56 waitable.events &= ~POLLIN;55 if (stream.failed()) { 56 stream.events &= ~POLLIN; 57 57 } else { 58 waitable.events |= POLLIN;58 stream.events |= POLLIN; 59 59 } 60 60 } else { 61 waitable.events &= ~POLLIN;61 stream.events &= ~POLLIN; 62 62 addLength(result); 63 63 } -
src/xplcommon/posix/ReadingBuffer.h
r6 r16 32 32 //------------------------------------------------------------------------------ 33 33 34 #include " WaitableBuffer.h"34 #include "StreamBuffer.h" 35 35 36 36 //------------------------------------------------------------------------------ … … 47 47 * amount of data read is 0, that indicates and end-of-file condition. 48 48 */ 49 class ReadingBuffer : public WaitableBuffer49 class ReadingBuffer : public StreamBuffer 50 50 { 51 51 protected: … … 53 53 * Construct the buffer. 54 54 */ 55 ReadingBuffer(size_t capacity, Buffered Waitable* waitable);55 ReadingBuffer(size_t capacity, BufferedStream* stream); 56 56 57 57 public: 58 58 /** 59 * Read into the buffer using the buffered waitableif possible.59 * Read into the buffer using the buffered stream if possible. 60 60 * 61 61 * If the buffer contains data, this function returns immediately … … 67 67 * end-of-file or end-of-connection condition. 68 68 * 69 * If the reading operation would block, the waitableis set up so69 * If the reading operation would block, the stream is set up so 70 70 * that it would read, and failure is returned. 71 71 * … … 76 76 bool read(); 77 77 78 friend class Buffered Waitable;78 friend class BufferedStream; 79 79 }; 80 80 … … 83 83 //------------------------------------------------------------------------------ 84 84 85 inline ReadingBuffer::ReadingBuffer(size_t capacity, 86 BufferedWaitable* waitable) : 87 WaitableBuffer(capacity, waitable) 85 inline ReadingBuffer::ReadingBuffer(size_t capacity, BufferedStream* stream) : 86 StreamBuffer(capacity, stream) 88 87 { 89 88 } -
src/xplcommon/posix/Socket.h
r14 r16 32 32 //------------------------------------------------------------------------------ 33 33 34 #include "Buffered Waitable.h"34 #include "BufferedStream.h" 35 35 36 36 //------------------------------------------------------------------------------ … … 47 47 * A buffered, waitable socket implementation. 48 48 */ 49 class Socket : public Buffered Waitable49 class Socket : public BufferedStream 50 50 { 51 51 private: … … 85 85 inline Socket::Socket(int domain, int type, Waiter* waiter, int protocol, 86 86 size_t readingCapacity, size_t writingCapacity) : 87 Buffered Waitable(waiter, socket(domain, type, protocol),87 BufferedStream(waiter, socket(domain, type, protocol), 88 88 readingCapacity, writingCapacity) 89 89 { … … 95 95 inline Socket::Socket(int fd, Waiter* waiter, 96 96 size_t readingCapacity, size_t writingCapacity) : 97 Buffered Waitable(waiter, fd, readingCapacity, writingCapacity)97 BufferedStream(waiter, fd, readingCapacity, writingCapacity) 98 98 { 99 99 } -
src/xplcommon/posix/StreamBuffer.h
r14 r16 28 28 // either expressed or implied, of the FreeBSD Project. 29 29 30 #ifndef XPLCOMMON_POSIX_ WAITABLEBUFFER_H31 #define XPLCOMMON_POSIX_ WAITABLEBUFFER_H30 #ifndef XPLCOMMON_POSIX_STREAMBUFFER_H 31 #define XPLCOMMON_POSIX_STREAMBUFFER_H 32 32 //------------------------------------------------------------------------------ 33 33 … … 35 35 #include "../Failable.h" 36 36 37 #include "Buffered Waitable.h"37 #include "BufferedStream.h" 38 38 39 39 //------------------------------------------------------------------------------ … … 44 44 45 45 /** 46 * Base class for buffers used by a Buffered Waitable.46 * Base class for buffers used by a BufferedStream. 47 47 */ 48 class WaitableBuffer : public ::xplcommon::Buffer,49 public ::xplcommon::FailableReference<WaitableBuffer>48 class StreamBuffer : public ::xplcommon::Buffer, 49 public ::xplcommon::FailableReference<StreamBuffer> 50 50 { 51 51 protected: 52 52 /** 53 * Our waitable.53 * Our buffered stream. 54 54 */ 55 Buffered Waitable& waitable;55 BufferedStream& stream; 56 56 57 57 protected: … … 59 59 * Construct the buffer with the given waitable. 60 60 */ 61 WaitableBuffer(size_t capacity, BufferedWaitable* waitable);61 StreamBuffer(size_t capacity, BufferedStream* stream); 62 62 63 63 private: … … 72 72 ::xplcommon::Failable& getFailable(); 73 73 74 friend class FailableReference< WaitableBuffer>;74 friend class FailableReference<StreamBuffer>; 75 75 }; 76 76 … … 79 79 //------------------------------------------------------------------------------ 80 80 81 inline WaitableBuffer::WaitableBuffer(size_t capacity, 82 BufferedWaitable* waitable) : 81 inline StreamBuffer::StreamBuffer(size_t capacity, BufferedStream* stream) : 83 82 Buffer(capacity), 84 waitable(*waitable)83 stream(*stream) 85 84 { 86 85 } … … 88 87 //------------------------------------------------------------------------------ 89 88 90 inline const ::xplcommon::Failable& WaitableBuffer::getFailable() const89 inline const ::xplcommon::Failable& StreamBuffer::getFailable() const 91 90 { 92 return waitable;91 return stream; 93 92 } 94 93 95 94 //------------------------------------------------------------------------------ 96 95 97 inline ::xplcommon::Failable& WaitableBuffer::getFailable()96 inline ::xplcommon::Failable& StreamBuffer::getFailable() 98 97 { 99 return waitable;98 return stream; 100 99 } 101 100 … … 105 104 106 105 //------------------------------------------------------------------------------ 107 #endif // XPLCOMMON_POSIX_ WAITABLEBUFFER_H106 #endif // XPLCOMMON_POSIX_STREAMBUFFER_H 108 107 109 108 // Local Variables: -
src/xplcommon/posix/WritingBuffer.cc
r14 r16 32 32 #include "WritingBuffer.h" 33 33 34 #include "Buffered Waitable.h"34 #include "BufferedStream.h" 35 35 36 36 #include <poll.h> … … 46 46 Buffer::reset(); 47 47 offset = 0; 48 waitable.events &= ~POLLOUT;48 stream.events &= ~POLLOUT; 49 49 } 50 50 … … 62 62 size_t toWrite = getLength() - offset; 63 63 64 ssize_t result = waitable.write(getData() + offset, toWrite);64 ssize_t result = stream.write(getData() + offset, toWrite); 65 65 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; 68 68 } else { 69 waitable.events |= POLLOUT;69 stream.events |= POLLOUT; 70 70 if (result>0) offset += result; 71 71 } -
src/xplcommon/posix/WritingBuffer.h
r6 r16 32 32 //------------------------------------------------------------------------------ 33 33 34 #include " WaitableBuffer.h"34 #include "StreamBuffer.h" 35 35 36 36 //------------------------------------------------------------------------------ … … 47 47 * has been written. In that case the buffer is automatically emptied. 48 48 */ 49 class WritingBuffer : public WaitableBuffer49 class WritingBuffer : public StreamBuffer 50 50 { 51 51 private: … … 59 59 * Construct the buffer. 60 60 */ 61 WritingBuffer(size_t capacity, Buffered Waitable* waitable);61 WritingBuffer(size_t capacity, BufferedStream* stream); 62 62 63 63 public: … … 69 69 /** 70 70 * Write the contents of the buffer using the associated buffered 71 * waitable.71 * stream. 72 72 * 73 73 * If the buffer is empty, the function returns indicating … … 79 79 * If not everything can be written and the write operation 80 80 * indicates that it would block, this function returns failure 81 * after the waitablehas been set up to handle the corresponding81 * after the stream has been set up to handle the corresponding 82 82 * poll events. 83 83 * … … 88 88 bool write(); 89 89 90 friend class Buffered Waitable;90 friend class BufferedStream; 91 91 }; 92 92 … … 95 95 //------------------------------------------------------------------------------ 96 96 97 inline WritingBuffer::WritingBuffer(size_t capacity, 98 BufferedWaitable* waitable): 99 WaitableBuffer(capacity, waitable), 97 inline WritingBuffer::WritingBuffer(size_t capacity, BufferedStream* stream): 98 StreamBuffer(capacity, stream), 100 99 offset(0) 101 100 {
Note:
See TracChangeset
for help on using the changeset viewer.