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,30 +41,31 @@
|
||||||
(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
|
||||||
(fx
|
(lambda ()
|
||||||
(inet_ntop
|
(let ([nread (recvfrom sock buf bufsize 'MSG_DEFAULT addr addrlen)])
|
||||||
'AF_INET
|
(fx
|
||||||
(ftype-pointer-address
|
(inet_ntop
|
||||||
(ftype-&ref sockaddr_in (sin_addr) addr))
|
'AF_INET
|
||||||
straddr
|
(ftype-pointer-address
|
||||||
straddrsize)
|
(ftype-&ref sockaddr_in (sin_addr) addr))
|
||||||
(ntohs (ftype-ref sockaddr_in (sin_port) addr))
|
straddr
|
||||||
buf nread)
|
straddrsize)
|
||||||
|
(ntohs (ftype-ref sockaddr_in (sin_port) addr))
|
||||||
|
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