FD's - Am I going nuts?

From: <dtillman_at_cannonexpress.com>
Date: Fri, 15 Jan 1999 17:04:38 -0600 (CST)

;; Is this a bug, or am I missing something?
;;
;; The following code is a port scan detector.
;;
;; It works great except that for every hit it allocates a new file
;; descriptor. I presume that is coming from my use of socket-dup
;; in s-handler. But, shouldn't this fd go away after socket-shutdown?
;;
;; What is the right thing to do here? Obviously, the code errors after
;; I run out of file descriptors.
;;
;; -Dave


(require "posix")
(require "socket")



;;(define *ports* '(79 109 110 143 220 4000 4004 6667 7321 8000))
(define *ports* '(4000 4004 6667 7321 8000))


(define *log-file* (open-output-file "dumbo.log"))


(define unix-date
  (lambda (format)
    (let* ((proc (run-process "/bin/date" format :output :pipe))
           (date (read-line (process-output proc))))
      (close-input-port (process-output proc))
      date)))



(define s-handler (lambda (s)
                    (let ((new-socket (socket-dup s)))
                      (socket-accept-connection new-s)
                      (format #t "~A Connection on port ~A from ~A~%"
                              (unix-date "+%b %m %T")
                              (socket-port-number new-s)
                              (socket-host-address new-s))
                      (flush)
                      (format *log-file* "~A Connection on port ~A from ~A~%"
                              (unix-date "+%b %m %T")
                              (socket-port-number new-s)
                              (socket-host-address new-s))
                      (flush *log-file*)
                      (close-input-port (socket-input new-s))
                      (close-output-port (socket-output new-s))
                      (socket-shutdown new-socket))))




(define *sockets* (map make-server-socket *ports*))
(define *handlers* (map (lambda (s)
                          (lambda ()
                            (s-handler s)))
                        *sockets*))

(map when-socket-ready *sockets* *handlers*)
(format *log-file* "dumbo: listening on ports ~A~%" *ports*)
(format #t "dumbo: listening on ports ~A~%" *ports*)
Received on Sat Jan 16 1999 - 00:04:47 CET

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST