public
Description: Pure Ruby implementation of an SFTP (protocols 1-6) client
Homepage: http://rubyforge.org/projects/net-ssh
Clone URL: git://github.com/jamis/net-sftp.git
Search Repo:
make Session#connect execute/enqueue the callback even if the session is 
already open/opening
jamis (author)
Fri Apr 25 20:09:32 -0700 2008
commit  d947cf5763809120415fdb6e68085171be0259d3
tree    427e44f7569aeda875c7b0f81f9511a859ba1ed8
parent  c6de5bcd99173eb018080af3a30928dffebcaaea
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 === *unreleased*
0
 
0
+* Allow Session#connect to be useful even in the open/opening states by invoking or queuing the callback block [Jamis Buck]
0
+
0
 * Allow custom properties to be set on upload/download initiation via the :properties option [Jamis Buck]
0
 
0
 * Custom properties on Download instances [Jamis Buck]
...
746
747
748
749
750
 
 
 
 
 
751
752
753
...
760
761
762
763
764
765
766
767
768
 
 
 
 
 
 
 
 
 
 
 
 
 
 
769
770
771
...
924
925
926
927
 
 
928
929
930
...
746
747
748
 
 
749
750
751
752
753
754
755
756
...
763
764
765
 
 
 
 
 
 
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
...
935
936
937
 
938
939
940
941
942
0
@@ -746,8 +746,11 @@ module Net; module SFTP
0
       end
0
 
0
       # Attempts to establish an SFTP connection over the SSH session given when
0
- # this object was instantiated. If the object is already open (or opening),
0
- # this does nothing.
0
+ # this object was instantiated. If the object is already open, this will
0
+ # simply execute the given block (if any), passing the SFTP session itself
0
+ # as argument. If the session is currently being opened, this will add
0
+ # the given block to the list of callbacks, to be executed when the session
0
+ # is fully open.
0
       #
0
       # This method does not block, and will return immediately. If you pass a
0
       # block to it, that block will be invoked when the connection has been
0
@@ -760,12 +763,20 @@ module Net; module SFTP
0
       # If you just want to block until the connection is ready, see the #connect!
0
       # method.
0
       def connect(&block)
0
- return unless state == :closed
0
- @state = :opening
0
- @channel = session.open_channel(&method(:when_channel_confirmed))
0
- @packet_length = nil
0
- @protocol = nil
0
- @on_ready = block
0
+ case state
0
+ when :open
0
+ block.call(self) if block
0
+ when :closed
0
+ @state = :opening
0
+ @channel = session.open_channel(&method(:when_channel_confirmed))
0
+ @packet_length = nil
0
+ @protocol = nil
0
+ @on_ready = Array(block)
0
+ else # opening
0
+ @on_ready << block if block
0
+ end
0
+
0
+ self
0
       end
0
 
0
       # Same as the #connect method, but blocks until the SFTP connection has
0
@@ -924,7 +935,8 @@ module Net; module SFTP
0
         @pending_requests = {}
0
 
0
         @state = :open
0
- @on_ready.call(self) if @on_ready
0
+ @on_ready.each { |callback| callback.call(self) }
0
+ @on_ready = nil
0
       end
0
 
0
       # Parses the packet, finds the associated Request instance, and tells

Comments

    No one has commented yet.