Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

threaded parserver

  • Loading branch information...
commit f6481ed49fb22fcbb88fd12698af1b4938df8c34 1 parent 6015211
@dimus dimus authored
Showing with 15 additions and 14 deletions.
  1. +15 −14 bin/parserver
View
29 bin/parserver
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.