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

Fix Capturing the given block using Kernel#proc #159

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions server/libs/dnser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ def initialize(host, port, cache=false)
# This method returns immediately, but spawns a background thread. The thread
# will recveive and parse DNS packets, create a transaction, and pass it to
# the caller's block.
def on_request()
def on_request(&block)
@thread = Thread.new() do |t|
begin
loop do
Expand Down Expand Up @@ -869,7 +869,7 @@ def on_request()

if(!transaction.sent)
begin
proc.call(transaction)
block.call(transaction)
rescue StandardError => e
puts("Caught an error: #{e}")
puts(e.backtrace())
Expand Down Expand Up @@ -912,7 +912,7 @@ def wait()
# Send out a query, asynchronously. This immediately returns, then, when the
# query is finished, the callback block is called with a DNSer::Packet that
# represents the response (or nil, if there was a timeout).
def DNSer.query(hostname, params = {})
def DNSer.query(hostname, params = {}, &block)
server = params[:server] || "8.8.8.8"
port = params[:port] || 53
type = params[:type] || DNSer::Packet::TYPE_A
Expand All @@ -930,10 +930,10 @@ def DNSer.query(hostname, params = {})

timeout(timeout) do
response = s.recv(65536)
proc.call(DNSer::Packet.parse(response))
block.call(DNSer::Packet.parse(response))
end
rescue Timeout::Error
proc.call(nil)
block.call(nil)
rescue Exception => e
puts("There was an exception sending a query for #{hostname} to #{server}:#{port}: #{e}")
ensure
Expand Down
4 changes: 2 additions & 2 deletions server/libs/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ def each_setting()

# Create a new setting, or replace an old one. This must be done before a
# setting is used.
def create(name, type, default_value, docs)
def create(name, type, default_value, docs, &block)
name = name.to_s()

@settings[name] = @settings[name] || {}

@settings[name][:type] = type
@settings[name][:watcher] = proc
@settings[name][:watcher] = block
@settings[name][:docs] = docs
@settings[name][:default] = @@mutators[type].call(default_value.to_s())

Expand Down
8 changes: 4 additions & 4 deletions server/libs/swindow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ class SWindow

# This function will trap the TSTP signal (suspend, ctrl-z) and, if possible,
# activate the parent window.
def SWindow._catch_suspend()
def SWindow._catch_suspend(&block)
orig_suspend = Signal.trap("TSTP") do
if(@@active)
@@active.deactivate()
end
end

proc.call()
block.call()

Signal.trap("TSTP", orig_suspend)
end
Expand Down Expand Up @@ -182,8 +182,8 @@ def children()

# Set the on_input callback - the function that will be called when input is
# received. Very important!
def on_input()
@callback = proc
def on_input(&block)
@callback = block
end

def with(params = {})
Expand Down
4 changes: 2 additions & 2 deletions server/tunnel_drivers/driver_dns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def DriverDNS.do_encoding(question, domains, response)
return response
end

def initialize(parent_window, host, port, domains, cache)
def initialize(parent_window, host, port, domains, cache, &block)
if(domains.nil?)
domains = []
end
Expand Down Expand Up @@ -313,7 +313,7 @@ def initialize(parent_window, host, port, domains, cache)
end

# Get the response
response = proc.call(name, max_length)
response = block.call(name, max_length)

if(response.length > max_length)
raise(DnscatException, "The handler returned too much data! This shouldn't happen, please report. (max = #{max_length}, returned = #{response.length}")
Expand Down