(def handle-request (s (o life threadlife*))
  (if (len< (pull dead srvthreads*) threadlimit*)
      (let (i o ip) (socket-accept s)
        (++ requests*)
        (= (requests/ip* ip) (+ 1 (or (requests/ip* ip) 0)))
        (let th (thread 
                  (if (throttle-ips* ip) (sleep (rand throttle-time*)))
                  (handle-request-thread i o ip))
          (push th srvthreads*)
          (thread (sleep life)
                  (unless (dead th) (prn "srv thread took too long"))
                  (break-thread th)
                  (close i o))))
      (sleep .2)))

From srv.arc ©