Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add callback to directly find out remote forwarding response #174

Merged
merged 1 commit into from Jul 18, 2014

Conversation

jkeiser
Copy link
Contributor

@jkeiser jkeiser commented Jul 18, 2014

When Net::SSH is used to ask for multiple remote forwardings at the same time, the typical polling loop (check if active_remotes has grown, assume the new active_remote is the response to our query) is insufficient. This adds a callback that will be called when a remote forwarding request is complete, so that you can record the response specifically to that request. The documentation says it well:

You may pass a block that will be called when the the port forward request receives a response. This block will be passed the remote_port that was actually bound to, or nil if the binding failed. If the block returns :no_exception, the "failed binding" exception will not be thrown.

If you want to block until the port is active, you could do something like this:

got_remote_port = nil
remote(port, host, remote_port, remote_host) do |actual_remote_port|
  got_remote_port = actual_remote_port || :error
  :no_exception # will yield the exception (if any) on my own thread
end
session.loop { !got_remote_port }
if got_remote_port == :error
  raise Net::SSH::Exception, "remote forwarding request failed"
end

I have included tests for the new functionality.

@delano
Copy link
Collaborator

delano commented Jul 18, 2014

Looks great, thanks. It'll be in the next release.

Not sure when that will be... still waiting on resolutions for #164 and #145.

delano added a commit that referenced this pull request Jul 18, 2014
Add callback to directly find out remote forwarding response
@delano delano merged commit 441d078 into net-ssh:master Jul 18, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants