123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- (use-modules (rnrs bytevectors)
- (fibers)
- (fibers channels)
- (ice-9 binary-ports)
- (ice-9 textual-ports)
- (ice-9 rdelim)
- (ice-9 match))
- (define (connect-to-server addrinfo)
- (let ((port (socket (addrinfo:fam addrinfo)
- (addrinfo:socktype addrinfo)
- (addrinfo:protocol addrinfo))))
-
- (setsockopt port IPPROTO_TCP TCP_NODELAY 1)
- (fcntl port F_SETFL (logior O_NONBLOCK (fcntl port F_GETFL)))
- (setvbuf port 'block 1024)
- (connect port (addrinfo:addr addrinfo))
- port))
- (define (client-loop addrinfo n num-connections)
- (let ((port (connect-to-server addrinfo))
- (test (string-append "test-" (number->string n))))
- (let lp ((m 0))
- (when (< m num-connections)
- (put-string port test)
- (put-char port #\newline)
- (force-output port)
- (let ((response (read-line port)))
- (unless (equal? test response)
- (close-port port)
- (error "Bad response: ~A (expected ~A)" response test))
- (lp (1+ m)))))
- (close-port port)))
- (define (run-ping-test num-clients num-connections)
-
-
- (let ((addrinfo (car (getaddrinfo "localhost" (number->string 11211)))))
- (map get-message
- (map (lambda (n)
- (let ((ch (make-channel)))
- (spawn-fiber
- (lambda ()
- (client-loop addrinfo n num-connections)
- (put-message ch 'done))
- #:parallel? #t)
- ch))
- (iota num-clients)))))
- (run-fibers
- (lambda ()
- (apply run-ping-test (map string->number (cdr (program-arguments))))))
|