 ! Copyright (C) 2011 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors byte-arrays io io.encodings.binary io.servers
-io.sockets kernel math memoize namespaces sequences ;
+io.sockets kernel math memoize namespaces sequences fry literals ;
 IN: benchmark.file-server
 
-: test-file-size ( -- n ) 26 2^ ;
+! Tweak these parameters to test different loads
+CONSTANT: #times 4
+
+! Max size here is 26 2^ 1 - because array-capacity limits on 32bit platforms
+CONSTANT: test-file-size $[ 26 2^ 1 - ]
 
 MEMO: test-file-bytes ( -- byte-array )
     test-file-size iota >byte-array ;

        f 0 <inet4> >>insecure ;

M: file-server handle-client*
    drop test-file-bytes output-stream get stream-write ;
    
ERROR: incorrect-#bytes ;



: file-server-benchmark ( -- )
    <file-server> start-server [
        [ #times ] dip
        server>address binary <client> drop [
            '[
                test-file-size _ stream-read length test-file-size =
                [ incorrect-#bytes ] unless
            ] times
        ] [
            stream-contents length 0 = [ incorrect-#bytes ] unless
        ] bi
    ] [ stop-server ] bi ;
    
MAIN: file-server-benchmark
