Skip to content

Instantly share code, notes, and snippets.

@bizenn
Created October 11, 2012 10:08
Show Gist options
  • Save bizenn/3871406 to your computer and use it in GitHub Desktop.
Save bizenn/3871406 to your computer and use it in GitHub Desktop.
echo server (prefork)
#!/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)
@bizenn
Copy link
Author

bizenn commented Oct 11, 2012

Koguro suggested using copy-port.

@bizenn
Copy link
Author

bizenn commented Oct 11, 2012

齊藤(Saitoh) suggested using list-tabulate instead of map+iota.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment