Permalink
Browse files

threaded parserver

  • Loading branch information...
dimus committed Aug 3, 2011
1 parent 6015211 commit f6481ed49fb22fcbb88fd12698af1b4938df8c34
Showing with 15 additions and 14 deletions.
  1. +15 −14 bin/parserver
View
@@ -79,20 +79,21 @@ puts "Running parser service on port #{OPTIONS[:port]}, output type is '#{OPTION
parser = ScientificNameParser.new
server = TCPServer.open(OPTIONS[:port]) # Socket to listen on a port
loop do # Servers run forever
- client = server.accept # Wait for a client to connect
- puts 'opening client'
- count = 0
- while a = client.readline rescue nil
- count += 1
- puts "parsed %s'th name" % count if count % 1000 == 0
- a.force_encoding("utf-8") if a && RUBY_VERSION_INT >= 19
- if ['end','exit','q', '.'].include? a.strip
- client.close
- break
+ Thread.start(server.accept) do |client|
+ puts 'opening client'
+ count = 0
+ while a = client.readline rescue nil
+ count += 1
+ puts "parsed %s'th name" % count if count % 1000 == 0
+ a.force_encoding("utf-8") if a && RUBY_VERSION_INT >= 19
+ if ['end','exit','q', '.'].include? a.strip
+ client.close
+ break
+ end
+ out = get_output(a, parser).strip
+ client.write(out + "\n") rescue break
end
- out = get_output(a, parser).strip
- client.write(out + "\n") rescue break
+ puts 'closing client'
+ client.close
end
- puts 'closing client'
- client.close
end

0 comments on commit f6481ed

Please sign in to comment.