Working recv and its nice

This commit is contained in:
Quentin 2020-07-09 18:00:50 +02:00
parent 1032ee7032
commit 19f1ced0d6
2 changed files with 5 additions and 4 deletions

View file

@ -1,13 +1,13 @@
; Convert a char* to a Scheme string
; Extracted from this paper:
; http://scheme2011.ucombinator.org/papers/Keep2011.pdf
(define (char*->string fptr)
(define (char*->string fptr maxsize)
(let f ([i 0])
(let ([c (ftype-ref char () fptr i)])
(if (char=? c #\nul)
(if (or (char=? c #\nul) (and (> maxsize 0) (>= i maxsize)))
(make-string i)
(let ([str (f (fx+ i 1))])
(string-set! str i c)str)))))
(string-set! str i c) str)))))
(define (alloc size fx)
(let ([v (foreign-alloc size)])

View file

@ -84,5 +84,6 @@
"host: ~a, port: ~a, size: ~a, buf: ~a~%"
host port size
(char*->string
(make-ftype-pointer char buf)))
(make-ftype-pointer char buf)
size))
))))