Created
October 11, 2012 10:08
-
-
Save bizenn/3871406 to your computer and use it in GitHub Desktop.
echo server (prefork)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env gosh | |
;;; -*- mode: scheme; coding: utf-8 -*- | |
(use srfi-1) | |
(use gauche.net) | |
(use gauche.uvector) | |
;; gosh echo.scm <num> | |
(define (main args) | |
(let* ((server (make-server-socket 'inet 9999 :reuse-addr? #t :backlog SOMAXCONN)) | |
(procs (list-tabulate (x->integer (cadr args)) | |
(lambda _ | |
(case (sys-fork) | |
((0) | |
(while (socket-accept server) => s | |
(call-with-client-socket s copy-port)) | |
(sys-exit 0)) | |
(else => values)))))) | |
(socket-close server) | |
(for-each sys-waitpid procs)) | |
0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
齊藤(Saitoh) suggested using list-tabulate instead of map+iota.