Peter Bex  committed ef6e25b

Switch to nonblocking I/O and get rid of bpf-read-timeout since it is useless for nonblocking I/O...

  • Participants
  • Parent commits 82739ea

Comments (0)

Files changed (1)

File bpf-interface.scm

   (bpf-open bpf-close bpf? bpf-buffer-length bpf-flush!
             bpf-interface bpf-interface-set! bpf-stats
             bpf-datalink-type bpf-datalink-type-set! bpf-list-datalink-types
-            bpf-read-timeout bpf-read-timeout-set! bpf-filter-set!)
+            bpf-filter-set!)
 (import chicken scheme foreign)
                      (make-property-condition 'bpf)
                      (make-property-condition 'i/o)
                      (make-property-condition 'file))))
-          (let* ((fd (condition-case (file-open fn (fx+ open/read open/write))
+          (let* ((mode (bitwise-ior open/read open/write open/nonblock))
+                 (fd (condition-case (file-open fn mode)
                        (e (exn i/o file) (lp (fx+ i 1) fn e))))
                  (bpf (make-bpf fd)))
             (set-finalizer! bpf bpf-close)
          ((foreign-lambda* unsigned-int (((c-pointer "u_int") p) (int i))
             "C_return(p[i]);") (location types) i))))))
-(define (bpf-read-timeout bpf)
-  (let ((tv (make-blob (foreign-value "sizeof(struct timeval)" int))))
-    (ioctl bpf BIOCGRTIMEOUT tv)
-    ((foreign-lambda* double (((c-pointer "struct timeval") tv))
-       "C_return(tv->tv_sec + tv->tv_usec / 1000000.0);") (location tv))))
-(define (bpf-read-timeout-set! bpf timeout)
-  (let ((tv (make-blob (foreign-value "sizeof(struct timeval)" int)))
-        (timeout (max 0 timeout)))
-    ((foreign-lambda* void (((c-pointer "struct timeval") tv) (double timeout))
-       "double i;"
-       "tv->tv_usec = (int)(modf(timeout, &i) * 1000000);"
-       "tv->tv_sec = (int)timeout;") (location tv) timeout)
-    (ioctl bpf BIOCSRTIMEOUT tv)
-    (void)))
 (define (bpf-stats bpf)
   (let ((st (make-blob (foreign-value "sizeof(struct bpf_stat)" int))))
     (ioctl bpf BIOCGSTATS st)