diff options
author | zzak <zzak@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-07-20 13:41:02 +0000 |
---|---|---|
committer | zzak <zzak@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-07-20 13:41:02 +0000 |
commit | b4489ae953601cceb30e5dbdac5fe213ecad1b75 (patch) | |
tree | 0e8bea2d6e4a0cdfc900c835653a83a2637ff740 /sample/drb | |
parent | 368cecc1517ba2a09b0413eeaf5c3ba9981de4db (diff) | |
download | ruby-b4489ae953601cceb30e5dbdac5fe213ecad1b75.tar.gz |
* sample/*: whitespace patch by Sergio Campama [Fixes GH-364]
https://github.com/ruby/ruby/pull/364
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42086 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sample/drb')
-rw-r--r-- | sample/drb/dbiff.rb | 22 | ||||
-rw-r--r-- | sample/drb/dchats.rb | 20 | ||||
-rw-r--r-- | sample/drb/dlogd.rb | 4 | ||||
-rw-r--r-- | sample/drb/http0.rb | 60 | ||||
-rw-r--r-- | sample/drb/http0serv.rb | 106 | ||||
-rw-r--r-- | sample/drb/old_tuplespace.rb | 74 | ||||
-rw-r--r-- | sample/drb/simpletuple.rb | 8 |
7 files changed, 147 insertions, 147 deletions
diff --git a/sample/drb/dbiff.rb b/sample/drb/dbiff.rb index b50edc0898..290eb1d28b 100644 --- a/sample/drb/dbiff.rb +++ b/sample/drb/dbiff.rb @@ -19,18 +19,18 @@ class Biff last = Time.now while true begin - sleep(@interval) - current = File::mtime(@filename) - if current > last - changed - begin - notify_observers(@filename, current) - rescue Error - end - last = current - end + sleep(@interval) + current = File::mtime(@filename) + if current > last + changed + begin + notify_observers(@filename, current) + rescue Error + end + last = current + end rescue - next + next end end end diff --git a/sample/drb/dchats.rb b/sample/drb/dchats.rb index ccb2c7c9c5..c07f748e99 100644 --- a/sample/drb/dchats.rb +++ b/sample/drb/dchats.rb @@ -47,16 +47,16 @@ class ChatServer msg2 = ">#{name}< #{str}" @mutex.synchronize do for m in @members.keys - begin - if m == there - @members[m].listen(msg2) - else - @members[m].listen(msg) - end - rescue - p $! - @members.delete(m) - end + begin + if m == there + @members[m].listen(msg2) + else + @members[m].listen(msg) + end + rescue + p $! + @members.delete(m) + end end end end diff --git a/sample/drb/dlogd.rb b/sample/drb/dlogd.rb index fef7ca0f1d..42f302e64e 100644 --- a/sample/drb/dlogd.rb +++ b/sample/drb/dlogd.rb @@ -21,8 +21,8 @@ class Logger def flush begin while(1) - @fp.puts(@queue.pop) - @fp.flush + @fp.puts(@queue.pop) + @fp.flush end ensure @fp.close diff --git a/sample/drb/http0.rb b/sample/drb/http0.rb index d4c9f6b7fb..e40d810311 100644 --- a/sample/drb/http0.rb +++ b/sample/drb/http0.rb @@ -6,20 +6,20 @@ module DRb module HTTP0 class StrStream def initialize(str='') - @buf = str + @buf = str end attr_reader :buf def read(n) - begin - return @buf[0,n] - ensure - @buf[0,n] = '' - end + begin + return @buf[0,n] + ensure + @buf[0,n] = '' + end end def write(s) - @buf.concat s + @buf.concat s end end @@ -29,47 +29,47 @@ module DRb def self.open(uri, config) unless /^http:/ =~ uri - raise(DRbBadScheme, uri) unless uri =~ /^http:/ - raise(DRbBadURI, 'can\'t parse uri:' + uri) + raise(DRbBadScheme, uri) unless uri =~ /^http:/ + raise(DRbBadURI, 'can\'t parse uri:' + uri) end ClientSide.new(uri, config) end class ClientSide def initialize(uri, config) - @uri = uri - @res = nil - @config = config - @msg = DRbMessage.new(config) - @proxy = ENV['HTTP_PROXY'] + @uri = uri + @res = nil + @config = config + @msg = DRbMessage.new(config) + @proxy = ENV['HTTP_PROXY'] end def close; end def alive?; false; end def send_request(ref, msg_id, *arg, &b) - stream = StrStream.new - @msg.send_request(stream, ref, msg_id, *arg, &b) - @reply_stream = StrStream.new - post(@uri, stream.buf) + stream = StrStream.new + @msg.send_request(stream, ref, msg_id, *arg, &b) + @reply_stream = StrStream.new + post(@uri, stream.buf) end def recv_reply - @msg.recv_reply(@reply_stream) + @msg.recv_reply(@reply_stream) end def post(url, data) - it = URI.parse(url) - path = [(it.path=='' ? '/' : it.path), it.query].compact.join('?') - http = Net::HTTP.new(it.host, it.port) - sio = StrStream.new - http.post(path, data, {'Content-Type'=>'application/octetstream;'}) do |str| - sio.write(str) - if @config[:load_limit] < sio.buf.size - raise TypeError, 'too large packet' - end - end - @reply_stream = sio + it = URI.parse(url) + path = [(it.path=='' ? '/' : it.path), it.query].compact.join('?') + http = Net::HTTP.new(it.host, it.port) + sio = StrStream.new + http.post(path, data, {'Content-Type'=>'application/octetstream;'}) do |str| + sio.write(str) + if @config[:load_limit] < sio.buf.size + raise TypeError, 'too large packet' + end + end + @reply_stream = sio end end end diff --git a/sample/drb/http0serv.rb b/sample/drb/http0serv.rb index 8318123fa9..9503a1790c 100644 --- a/sample/drb/http0serv.rb +++ b/sample/drb/http0serv.rb @@ -8,111 +8,111 @@ module DRb def self.open_server(uri, config) unless /^http:/ =~ uri - raise(DRbBadScheme, uri) unless uri =~ /^http:/ - raise(DRbBadURI, 'can\'t parse uri:' + uri) + raise(DRbBadScheme, uri) unless uri =~ /^http:/ + raise(DRbBadURI, 'can\'t parse uri:' + uri) end Server.new(uri, config) end class Callback < WEBrick::HTTPServlet::AbstractServlet def initialize(config, drb) - @config = config - @drb = drb - @queue = Queue.new + @config = config + @drb = drb + @queue = Queue.new end def do_POST(req, res) - @req = req - @res = res - @drb.push(self) - @res.body = @queue.pop - @res['content-type'] = 'application/octet-stream;' + @req = req + @res = res + @drb.push(self) + @res.body = @queue.pop + @res['content-type'] = 'application/octet-stream;' end def req_body - @req.body + @req.body end def reply(body) - @queue.push(body) + @queue.push(body) end def close - @queue.push('') + @queue.push('') end end class Server def initialize(uri, config) - @uri = uri - @config = config - @queue = Queue.new - setup_webrick(uri) + @uri = uri + @config = config + @queue = Queue.new + setup_webrick(uri) end attr_reader :uri def close - @server.shutdown if @server - @server = nil + @server.shutdown if @server + @server = nil end def push(callback) - @queue.push(callback) + @queue.push(callback) end def accept - client = @queue.pop - ServerSide.new(client, @config) + client = @queue.pop + ServerSide.new(client, @config) end def setup_webrick(uri) - logger = WEBrick::Log::new($stderr, WEBrick::Log::FATAL) - u = URI.parse(uri) - s = WEBrick::HTTPServer.new(:Port => u.port, - :AddressFamily => Socket::AF_INET, - :BindAddress => u.host, - :Logger => logger, - :ServerType => Thread) - s.mount(u.path, Callback, self) - @server = s - s.start + logger = WEBrick::Log::new($stderr, WEBrick::Log::FATAL) + u = URI.parse(uri) + s = WEBrick::HTTPServer.new(:Port => u.port, + :AddressFamily => Socket::AF_INET, + :BindAddress => u.host, + :Logger => logger, + :ServerType => Thread) + s.mount(u.path, Callback, self) + @server = s + s.start end end class ServerSide def initialize(callback, config) - @callback = callback - @config = config - @msg = DRbMessage.new(@config) - @req_stream = StrStream.new(@callback.req_body) + @callback = callback + @config = config + @msg = DRbMessage.new(@config) + @req_stream = StrStream.new(@callback.req_body) end def close - @callback.close if @callback - @callback = nil + @callback.close if @callback + @callback = nil end def alive?; false; end def recv_request - begin - @msg.recv_request(@req_stream) - rescue - close - raise $! - end + begin + @msg.recv_request(@req_stream) + rescue + close + raise $! + end end def send_reply(succ, result) - begin - return unless @callback - stream = StrStream.new - @msg.send_reply(stream, succ, result) - @callback.reply(stream.buf) - rescue - close - raise $! - end + begin + return unless @callback + stream = StrStream.new + @msg.send_reply(stream, succ, result) + @callback.reply(stream.buf) + rescue + close + raise $! + end end end end diff --git a/sample/drb/old_tuplespace.rb b/sample/drb/old_tuplespace.rb index 0da9fa84c3..9c10a34527 100644 --- a/sample/drb/old_tuplespace.rb +++ b/sample/drb/old_tuplespace.rb @@ -11,7 +11,7 @@ class TupleSpace @list = list @check_idx = [] @list.each_with_index do |x, i| - @check_idx.push i if x + @check_idx.push i if x end @size = @list.size end @@ -22,9 +22,9 @@ class TupleSpace def match(tuple) return nil if tuple.size != self.size @check_idx.each do |i| - unless @list[i] === tuple[i] - return false - end + unless @list[i] === tuple[i] + return false + end end return true end @@ -47,13 +47,13 @@ class TupleSpace found = false @waiting[sz] = @waiting[sz].find_all { |x| if x[0].match(tuple) - begin - x[1].wakeup - rescue ThreadError - end - false + begin + x[1].wakeup + rescue ThreadError + end + false else - true + true end } end @@ -77,8 +77,8 @@ class TupleSpace found = false @que[sz].each_with_index do |x, i| if template.match(x) - found = true - break + found = true + break end end return nil unless found @@ -110,17 +110,17 @@ class TupleSpace def in(template, non_block=false) begin loop do - Thread.critical = true - tuple = get_que(template) - unless tuple - if non_block - raise ThreadError, "queue empty" - end - put_waiting(template, Thread.current) - Thread.stop - else - return tuple - end + Thread.critical = true + tuple = get_que(template) + unless tuple + if non_block + raise ThreadError, "queue empty" + end + put_waiting(template, Thread.current) + Thread.stop + else + return tuple + end end ensure Thread.critical = false @@ -155,11 +155,11 @@ if __FILE__ == $0 def server(ts, id) Thread.start { loop do - req = ts.in(['req', nil, nil]) - ac = req[1] - num = req[2] - sleep id - ts.out([ac, id, num, num * num]) + req = ts.in(['req', nil, nil]) + ac = req[1] + num = req[2] + sleep id + ts.out([ac, id, num, num * num]) end } end @@ -168,14 +168,14 @@ if __FILE__ == $0 Thread.start { ac = Object.new tuples = (1..10).collect { |i| - ['req', ac, i * 10 + n] + ['req', ac, i * 10 + n] } ts.out(*tuples) ts.out(tuples[0]) puts "out: #{n}" 11.times do |i| - ans = ts.in([ac, nil, nil, nil]) - puts "client(#{n}) server(#{ans[1]}) #{ans[2]} #{ans[3]}" + ans = ts.in([ac, nil, nil, nil]) + puts "client(#{n}) server(#{ans[1]}) #{ans[2]} #{ans[3]}" end } end @@ -183,12 +183,12 @@ if __FILE__ == $0 def watcher(ts) Thread.start { loop do - begin - sleep 1 - p ts.rd(['req', nil, nil], true) - rescue ThreadError - puts "'req' not found." - end + begin + sleep 1 + p ts.rd(['req', nil, nil], true) + rescue ThreadError + puts "'req' not found." + end end } end diff --git a/sample/drb/simpletuple.rb b/sample/drb/simpletuple.rb index 1b9b7a35a7..bfbd86e665 100644 --- a/sample/drb/simpletuple.rb +++ b/sample/drb/simpletuple.rb @@ -58,10 +58,10 @@ if __FILE__ == $0 def server(ts) Thread.start { loop do - req = ts.in('req') - ac = req[0] - num = req[1] - ts.out(ac, num * num) + req = ts.in('req') + ac = req[0] + num = req[1] + ts.out(ac, num * num) end } end |