Changeset 3850
- Timestamp:
- 08/04/08 14:23:41 (4 months ago)
- Files:
-
- trunk/tango/io/ThreadConduit.d (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/tango/io/ThreadConduit.d
r3615 r3850 13 13 private import tango.core.Exception; 14 14 15 public import tango.io. model.IConduit;15 public import tango.io.Conduit; 16 16 17 17 /** … … 36 36 * t.join(); 37 37 */ 38 class ThreadConduit : IConduit38 class ThreadConduit : Conduit 39 39 { 40 40 private bool _closed; … … 60 60 61 61 /** 62 * Implements IConduit.input (covariant)63 */64 ThreadConduit input()65 {66 return this;67 }68 69 /**70 * Implements IConduit.output (covariant)71 */72 ThreadConduit output()73 {74 return this;75 }76 77 /**78 62 * Implements IConduit.bufferSize 79 63 * … … 91 75 * Implements IConduit.toString 92 76 * 93 * Returns " <thread conduit>"77 * Returns "<thread conduit>" 94 78 */ 95 79 char[] toString() … … 102 86 * closed. 103 87 */ 104 bool isAlive()88 override bool isAlive() 105 89 { 106 90 synchronized(_mutex) … … 152 136 _condition.notifyAll(); 153 137 } 154 }155 156 /**157 * Throw an IOException with the given message.158 */159 void error(char[] msg)160 {161 throw new IOException(msg);162 }163 164 /**165 * Implements InputStream.conduit and OutputStream.conduit (covariant)166 */167 ThreadConduit conduit()168 {169 return this;170 }171 172 /**173 * Close the write end of the conduit. Same as detach()174 */175 void close()176 {177 detach();178 138 } 179 139 … … 230 190 return result; 231 191 } 232 }233 234 /**235 * Implements InputStream.load236 *237 * Load the bits from a stream, and return them all in an array. The dst238 * array can be provided as an option, which will be expanded as necessary239 * to consume the input.240 *241 * Returns an array representing the content, and throws IOException on242 * error243 */244 void[] load(void[] dst = null)245 {246 //247 // copied from Conduit.load248 //249 auto chunk = 0;250 auto index = 0;251 252 while (chunk != Eof)253 {254 if (dst.length - index < 1024)255 dst.length = dst.length + 16 * 1024;256 257 chunk = read (dst[index .. $]);258 index += chunk;259 }260 261 return dst [0 .. index - chunk];262 192 } 263 193 … … 325 255 } 326 256 } 327 328 /**329 * Implements OutputStream.copy330 *331 * Transfer the content of another stream to this one. Returns a reference332 * to this class, and throws IOException on failure.333 */334 ThreadConduit copy(InputStream src)335 {336 //337 // copied from Conduit338 //339 uint len = 0;340 auto tmp = new void [bufferSize];341 while ((len = src.read(tmp)) != IConduit.Eof)342 {343 auto p = tmp.ptr;344 for (uint j; len > 0; len -= j, p += j)345 if ((j = write (p[0..len])) is IConduit.Eof)346 error ("ThreadConduit.copy :: Eof while writing to: "~toString);347 }348 delete tmp;349 return this;350 }351 352 /**353 * Implements OutputStream.flush354 *355 * Since there is no callable sink, this is a noop.356 */357 ThreadConduit flush()358 {359 return this;360 }361 257 }












