Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changeset 3850

Show
Ignore:
Timestamp:
08/04/08 14:23:41 (4 months ago)
Author:
schveiguy
Message:

Updated to inherit from Conduit, now that Conduit is decoupled from ISelectable.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tango/io/ThreadConduit.d

    r3615 r3850  
    1313private import tango.core.Exception; 
    1414 
    15 public import tango.io.model.IConduit; 
     15public import tango.io.Conduit; 
    1616 
    1717/** 
     
    3636 * t.join(); 
    3737 */ 
    38 class ThreadConduit : IConduit 
     38class ThreadConduit : Conduit 
    3939{ 
    4040    private bool _closed; 
     
    6060 
    6161    /** 
    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     /** 
    7862     * Implements IConduit.bufferSize 
    7963     * 
     
    9175     * Implements IConduit.toString 
    9276     * 
    93      * Returns "<thread conduit>
     77     * Returns "&lt;thread conduit&gt;
    9478     */ 
    9579    char[] toString() 
     
    10286     * closed. 
    10387     */ 
    104     bool isAlive() 
     88    override bool isAlive() 
    10589    { 
    10690        synchronized(_mutex) 
     
    152136            _condition.notifyAll(); 
    153137        } 
    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(); 
    178138    } 
    179139 
     
    230190            return result; 
    231191        } 
    232     } 
    233  
    234     /** 
    235      * Implements InputStream.load 
    236      * 
    237      * Load the bits from a stream, and return them all in an array. The dst 
    238      * array can be provided as an option, which will be expanded as necessary 
    239      * to consume the input. 
    240      * 
    241      * Returns an array representing the content, and throws IOException on 
    242      * error 
    243      */ 
    244     void[] load(void[] dst = null) 
    245     { 
    246         // 
    247         // copied from Conduit.load 
    248         // 
    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]; 
    262192    } 
    263193 
     
    325255        } 
    326256    } 
    327  
    328     /** 
    329      * Implements OutputStream.copy 
    330      * 
    331      * Transfer the content of another stream to this one. Returns a reference 
    332      * to this class, and throws IOException on failure. 
    333      */ 
    334     ThreadConduit copy(InputStream src) 
    335     { 
    336         // 
    337         // copied from Conduit 
    338         // 
    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.flush 
    354      * 
    355      * Since there is no callable sink, this is a noop. 
    356      */ 
    357     ThreadConduit flush() 
    358     { 
    359         return this; 
    360     } 
    361257}