-! Copyright (C) 2008 Slava Pestov.
+! Copyright (C) 2008, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors kernel math threads io io.sockets
 io.encodings.ascii io.streams.duplex debugger tools.time

IN: benchmark.sockets

SYMBOL: counter
SYMBOL: port-promise
SYMBOL: server

CONSTANT: number-of-requests 1000

: server-addr ( -- addr )
    "127.0.0.1" port-promise get ?promise <inet4> ;

: server-loop ( server -- )
    dup accept drop [


: clients ( n -- )
    dup pprint " clients: " write [
        <promise> server-promise set
        dup <count-down> counter set
        "127.0.0.1" 0 <inet4> ascii <server>
        [ server set ] [ addr>> port>> port set ] bi

        [ simple-server ] "Simple server" spawn drop
        [ [ simple-client ] "Simple client" spawn drop ] times

        counter get await
        stop-server
        server-promise get ?promise drop
    ] benchmark . flush ;

: socket-benchmarks ( -- )
