Fix for JRUBY-2882. Handle error messages related to constructors better
[jruby.git] / bench / shootout / tcprequest.ruby
blobf485b4dc8d8c36b176766507f63473249498bf61
1 #!/usr/bin/ruby
2 #### The Great Computer Language Shootout
3 #### http://shootout.alioth.debian.org/
4 ####
5 #### Contributed by Robbert Haarman
6 #### Modified by Ian Osgood
8 require 'socket'
10 N = Integer(ARGV[0] || 10)
11 M = 100
12 REPLY_SIZE = 4096
13 REQUEST_SIZE = 1
14 Host = 'localhost'
15 Port = 12345
17 sock = TCPServer.new Host, Port
18 if fork
19 # Parent process
20 conn = sock.accept
21 reply = 'x' * REPLY_SIZE
22 while true
23 request = conn.read REQUEST_SIZE
24 break if request == nil
25 conn.write reply
26 end
27 else
28 # Child process
29 conn = TCPSocket.new Host, Port
30 replies = 0
31 bytes = 0
32 n = N * M
33 request = 'x' * REQUEST_SIZE
34 while n > 0
35 n = n - 1
36 conn.write request
37 reply = conn.read REPLY_SIZE
38 replies = replies + 1
39 bytes = bytes + reply.length
40 end
41 conn.close
42 puts "replies: #{replies}\tbytes: #{bytes}"
43 end
45 sock.close