summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Bex <peter@more-magic.net>2013-05-11 16:25:11 +0200
committerPeter Bex <peter@more-magic.net>2016-03-04 21:38:49 +0100
commit1ede92cde15a9a9bc8acd46805a6b623d8fd8f4a (patch)
tree24306c5a6ed2863a0f51eefadbc1d4fc900e992f
parent813eb3cc32c292c79078f73fc409c68eb3c75d7a (diff)
downloadbpf-1ede92cde15a9a9bc8acd46805a6b623d8fd8f4a.tar.gz
Switch to nonblocking I/O and get rid of bpf-read-timeout since it is useless for nonblocking I/O...
-rw-r--r--bpf-interface.scm21
1 files changed, 3 insertions, 18 deletions
diff --git a/bpf-interface.scm b/bpf-interface.scm
index 68c9984..0277140 100644
--- a/bpf-interface.scm
+++ b/bpf-interface.scm
@@ -9,7 +9,7 @@
(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)
@@ -85,7 +85,8 @@
(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)
@@ -178,22 +179,6 @@
((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)