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

Changeset 3447

Show
Ignore:
Timestamp:
04/20/08 07:35:06 (8 months ago)
Author:
lmartin92
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/lmartin/ftp/tango/net/ftp/FtpClient.d

    r3411 r3447  
    55 * License: $(BSD Liscense) 
    66 */ 
     7 
     8//name the module 
    79module tango.net.ftp.FtpClient; 
    810 
     11//import all needed files 
    912private { 
    1013    import tango.net.ftp.Telnet; 
     
    231234    char[] currFile_ = ""; 
    232235    SocketConduit dataSocket_; 
     236    TimeSpan timeout = TimeSpan.millis(5000); 
    233237 
    234238    public FtpFeature[] supportedFeatures() { 
     
    282286    body { 
    283287 
    284         if(socket !is null) { 
    285             socket.close(); 
     288        if(socket_ !is null) { 
     289            socket_.close(); 
    286290        } 
    287291 
     
    312316 
    313317    public void close() { 
    314         if(socket !is null) { 
     318        if(socket_ !is null) { 
    315319            try { 
    316320                sendCommand("QUIT"); 
     
    320324            } 
    321325 
    322             socket.close(); 
     326            socket_.close(); 
    323327 
    324328            delete supportedFeatures_; 
    325             delete socket
     329            delete socket_
    326330        } 
    327331    } 
     
    540544 
    541545    public void sendCommand(char[] command, char[][] parameters...) { 
    542         assert(this.socket !is null); 
     546        assert(this.socket_ !is null); 
    543547 
    544548        char[] socketCommand = command; 
     
    577581 
    578582    public FtpResponse readResponse() { 
    579         assert(this.socket !is null); 
     583        assert(this.socket_ !is null); 
    580584 
    581585        // Pick a time at which we stop reading.  It can't take too long, but it could take a bit for the whole response. 
     
    729733            // Connecting to the same host. 
    730734            IPv4Address 
    731             remote = cast(IPv4Address) this.socket.socket.remoteAddress(); 
     735            remote = cast(IPv4Address) this.socket_.socket.remoteAddress(); 
    732736            assert(remote !is null); 
    733737 
     
    748752 
    749753            IPv4Address 
    750             remote = cast(IPv4Address) this.socket.socket.remoteAddress(); 
     754            remote = cast(IPv4Address) this.socket_.socket.remoteAddress(); 
    751755            assert(remote !is null); 
    752756 
     
    809813        return this.isSupported(command); 
    810814    } 
    811 
     815 
     816    /// Prepare a data socket for use. 
     817    /// 
     818    /// This modifies the socket in some cases. 
     819    /// 
     820    /// Params: 
     821    ///    data =            the data listener socket 
     822    protected void prepareDataSocket(inout SocketConduit data) { 
     823        switch(this.inf_.type) { 
     824        default: 
     825            exception("unknown connection type"); 
     826 
     827        case FtpConnectionType.active: 
     828            Socket new_data = null; 
     829 
     830            SocketSet set = new SocketSet(); 
     831            scope(exit) 
     832            delete set; 
     833 
     834            // At end_time, we bail. 
     835            Time end_time = Clock.now + this.timeout; 
     836 
     837            while(Clock.now < end_time) { 
     838                set.reset(); 
     839                set.add(data.socket); 
     840 
     841                // Can we accept yet? 
     842                int code = Socket.select(set, null, null, this.timeout); 
     843                if(code == -1 || code == 0) 
     844                    break; 
     845 
     846                new_data = data.socket.accept(); 
     847                break; 
     848            } 
     849 
     850            if(new_data is null) 
     851                throw new FtpException("CLIENT: No connection from server", 
     852                "420"); 
     853 
     854            // We don't need the listener anymore. 
     855            data.socket.shutdown(SocketShutdown.BOTH); 
     856            data.detach(); 
     857 
     858            // This is the actual socket. 
     859            data.connect(new_data.localAddress()); 
     860            break; 
     861 
     862        case FtpConnectionType.passive: 
     863            break; 
     864        } 
     865    } 
     866
     867 
     868debug(UnitTest) { 
     869    import tango.io.Stdout; 
     870 
     871    void main() { 
     872        Stdout("Testing the new parts in FtpClient.d").newline.flush; 
     873        FTPConnection conn = new FTPConnection("ftp.digitalmars.com"); 
     874        Stdout("Connecting works!").newline.flush; 
     875    } 
     876
  • branches/lmartin/ftp/tango/net/ftp/Telnet.d

    r3393 r3447  
    1414 
    1515    /// The Socket Conduit that is used to send commands. 
    16     SocketConduit socket; 
     16    SocketConduit socket_; 
     17    char[8 * 1024] dst; //for reading from the socket_ 
    1718 
    1819    abstract void exception(char[] message); 
     
    3031    ///    buf =             the bytes to send 
    3132    void sendData(void[] buf) { 
    32         socket.write(buf); 
     33        socket_.write(buf); 
    3334    } 
    3435 
     
    3738    /// Returns:             the line read 
    3839    char[] readLine() { 
    39         void[8 * 1024] dst
    40         socket.read(dst)
    41         return dst
     40        socket_.read(dst)
     41        char[] toReturn = dst.dup
     42        return toReturn
    4243    } 
    4344 
     
    4849    /// returns the SocketConduit this class is using 
    4950    SocketConduit findAvailableServer(char[] hostname, int port) { 
    50         socket = new SocketConduit(); 
    51         socket.connect(new InternetAddress(hostname, port)); 
     51        socket_ = new SocketConduit(); 
     52        socket_.connect(new InternetAddress(hostname, port)); 
    5253 
    53         return socket
     54        return socket_
    5455    } 
    5556