Loop works but host not filled :(
This commit is contained in:
parent
c4e87de70f
commit
f9b8f8a869
1 changed files with 19 additions and 20 deletions
|
@ -41,21 +41,22 @@
|
||||||
(ftype-sizeof sockaddr_in))))))
|
(ftype-sizeof sockaddr_in))))))
|
||||||
|
|
||||||
(define (udpsock-readblock sock fx)
|
(define (udpsock-readblock sock fx)
|
||||||
(let*
|
(letrec*
|
||||||
([bufsize 1500] [straddrsize 255]
|
([bufsize 1500] [straddrsize 255]
|
||||||
[buf (foreign-alloc bufsize)]
|
[buf (foreign-alloc bufsize)]
|
||||||
[straddr (make-ftype-pointer
|
[straddr (make-ftype-pointer char
|
||||||
char
|
|
||||||
(foreign-alloc straddrsize))]
|
(foreign-alloc straddrsize))]
|
||||||
[addrlen (make-ftype-pointer
|
[addrlen (make-ftype-pointer int
|
||||||
int
|
|
||||||
(foreign-alloc (ftype-sizeof int)))]
|
(foreign-alloc (ftype-sizeof int)))]
|
||||||
|
[_ (ftype-set! int () addrlen (ftype-sizeof sockaddr_in))]
|
||||||
[addr (make-ftype-pointer
|
[addr (make-ftype-pointer
|
||||||
sockaddr_in
|
sockaddr_in
|
||||||
(foreign-alloc (ftype-sizeof sockaddr_in)))]
|
(foreign-alloc (ftype-sizeof sockaddr_in)))]
|
||||||
[nread (recvfrom sock buf bufsize 'MSG_DEFAULT addr addrlen)])
|
[loop (lambda (ifx) (cond ((ifx) (loop ifx)) (#t #t)))])
|
||||||
|
|
||||||
; FIXME add a loop and check fx output to know if we continue
|
(loop
|
||||||
|
(lambda ()
|
||||||
|
(let ([nread (recvfrom sock buf bufsize 'MSG_DEFAULT addr addrlen)])
|
||||||
(fx
|
(fx
|
||||||
(inet_ntop
|
(inet_ntop
|
||||||
'AF_INET
|
'AF_INET
|
||||||
|
@ -64,7 +65,7 @@
|
||||||
straddr
|
straddr
|
||||||
straddrsize)
|
straddrsize)
|
||||||
(ntohs (ftype-ref sockaddr_in (sin_port) addr))
|
(ntohs (ftype-ref sockaddr_in (sin_port) addr))
|
||||||
buf nread)
|
buf nread))))
|
||||||
|
|
||||||
(foreign-free (ftype-pointer-address straddr))
|
(foreign-free (ftype-pointer-address straddr))
|
||||||
(foreign-free (ftype-pointer-address addrlen))
|
(foreign-free (ftype-pointer-address addrlen))
|
||||||
|
@ -78,11 +79,9 @@
|
||||||
(udpsock-readblock
|
(udpsock-readblock
|
||||||
sock
|
sock
|
||||||
(lambda (host port buf size)
|
(lambda (host port buf size)
|
||||||
(printf "~a~%" size)
|
|
||||||
(printf "~a~%" port)
|
|
||||||
(printf "~a~%" host)
|
|
||||||
(printf
|
(printf
|
||||||
"~a~%"
|
"host: ~a, port: ~a, size: ~a, buf: ~a~%"
|
||||||
|
host port size
|
||||||
(char*->string
|
(char*->string
|
||||||
(make-ftype-pointer char buf)))
|
(make-ftype-pointer char buf)))
|
||||||
))))
|
))))
|
||||||
|
|
Loading…
Reference in a new issue