Changeset 31:bbd688924703 in xplcommon for src
- Timestamp:
- 01/02/13 13:58:25 (12 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- src/xplcommon
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/xplcommon/BlockingStream.cc
r30 r31 46 46 //------------------------------------------------------------------------------ 47 47 48 bool BlockingStream::isInterrupted()48 inline bool BlockingStream::checkInterrupted() 49 49 { 50 if (failed()) return false;51 52 50 if (!interrupted) { 53 51 interrupted = event.check(); … … 83 81 //------------------------------------------------------------------------------ 84 82 83 bool BlockingStream::skip(size_t length) 84 { 85 ReadingBuffer& readingBuffer = stream.getReadingBuffer(); 86 while (length>0) { 87 size_t toSkip = min(length, readingBuffer.getLength() - readingOffset); 88 readingOffset += toSkip; 89 length -= toSkip; 90 91 if (length!=0) { 92 if (!fill()) return false; 93 } 94 } 95 96 return true; 97 } 98 99 //------------------------------------------------------------------------------ 100 85 101 bool BlockingStream::write(const void* src, size_t length) 86 102 { … … 105 121 { 106 122 WritingBuffer& writingBuffer = stream.getWritingBuffer(); 107 while ( !failed()) {108 if ( isInterrupted()) return false;123 while (*this) { 124 if (checkInterrupted()) return false; 109 125 110 126 if (writingBuffer.write()) { … … 112 128 } else if (writingBuffer.failed()) { 113 129 setErrorCode(writingBuffer.getErrorCode()); 114 return false;115 130 } else { 116 131 Waiter* waiter = stream.getWaiter(); … … 132 147 readingBuffer.reset(); 133 148 readingOffset = 0; 134 while ( true) {135 if ( isInterrupted()) return false;149 while (*this) { 150 if (checkInterrupted()) return false; 136 151 137 152 if (readingBuffer.read()) { 138 return !readingBuffer.isEmpty(); 153 eof = readingBuffer.isEmpty(); 154 return !eof; 139 155 } else if (readingBuffer.failed()) { 140 156 setErrorCode(readingBuffer.getErrorCode()); 141 return false;142 157 } else { 143 158 Waiter* waiter = stream.getWaiter(); … … 149 164 } 150 165 } 166 return false; 151 167 } 152 168 -
src/xplcommon/BlockingStream.h
r30 r31 35 35 36 36 #include "BufferedStream.h" 37 37 38 #include "Waiter.h" 38 39 #include "WaitableEvent.h" … … 76 77 size_t readingOffset; 77 78 79 /** 80 * Indicate if the end-of-file has been reached while reading. 81 */ 82 bool eof; 83 78 84 public: 79 85 /** … … 83 89 */ 84 90 BlockingStream(BufferedStream& stream); 91 92 /** 93 * Determine if the stream has neither failed nor been 94 * interrupted. 95 */ 96 operator bool() const; 85 97 86 98 /** … … 102 114 */ 103 115 bool read(void* dest, size_t length); 116 117 /** 118 * Skip the given number of bytes. 119 */ 120 bool skip(size_t length); 104 121 105 122 /** … … 125 142 */ 126 143 bool fill(); 144 145 /** 146 * Check for the stream being interrupted. 147 * 148 * @return if the stream is interrupted, false otherwise 149 */ 150 bool checkInterrupted(); 127 151 }; 128 152 … … 135 159 event(stream.getWaiter()), 136 160 interrupted(false), 137 readingOffset(0) 161 readingOffset(0), 162 eof(false) 138 163 { 164 } 165 166 //------------------------------------------------------------------------------ 167 168 inline BlockingStream::operator bool() const 169 { 170 return !failed() && !interrupted && !eof; 139 171 } 140 172 … … 144 176 { 145 177 event.fire(); 178 } 179 180 //------------------------------------------------------------------------------ 181 182 inline bool BlockingStream::isInterrupted() 183 { 184 return interrupted; 146 185 } 147 186 -
src/xplcommon/Makefile.am
r30 r31 11 11 libxplcommon_la_SOURCES= \ 12 12 PseudoRandom.cc \ 13 BlockingStream.cc 13 BlockingStream.cc \ 14 DataStream.cc 14 15 15 16 if TARGET_API_POSIX … … 39 40 LocalConnector.h \ 40 41 LocalClientSocket.h \ 41 BlockingStream.h 42 BlockingStream.h \ 43 DataStream.h
Note:
See TracChangeset
for help on using the changeset viewer.