Check-in [791b935228]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:improved nn-recv
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:791b935228419abe10beb87163405a52d77a8913
User & Date: aldo 2018-12-09 15:18:34
Context
2018-12-09
15:19
added bytevector to json->string outputs verbatim check-in: 2f15dd43ce user: aldo tags: trunk
15:18
improved nn-recv check-in: 791b935228 user: aldo tags: trunk
15:17
added scgi-before-fork-hook check-in: 04a3625e95 user: aldo tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to nanomsg.sls.

343
344
345
346
347
348
349

















350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366

367
368
369
370
371
372
373
 ;;     (let ([c (ftype-ref char () fptr i)])
 ;;       (if (or (char=? c #\nul) (and bytes (>= (+ 1 i) (car bytes))))
 ;; 	   (make-string i)
 ;; 	   (let ([str (f (fx+ i 1))])
 ;; 	     (string-set! str i c)
 ;; 	     str)))))


















 (define (nn-recv s buf len flags)
   (define b #f)
   (define r #f)
   (dynamic-wind 
       (lambda ()
	 (set! b (make-ftype-pointer void* (foreign-alloc (ftype-sizeof void*))))
	 (set! r (nn-recv% s (ftype-pointer-address b) len flags)))
       (lambda ()
	 (if (and r (> r 0))
	     (let ([c (make-ftype-pointer char (ftype-ref void* () b))])
	       (set-box! buf (char*->bytevector c r)))
	     (set-box! buf #f)))
       (lambda ()
	 (if (and r (> r 0))
	     (nn-freemsg (ftype-ref void* () b)))
	 (if b (foreign-free (ftype-pointer-address b)))))
   r)


 (define-nn-func int nn-sendmsg ((s int) (msghdr (* nn-msghdr)) (flags int))
   "nn_sendmsg")

 (define-nn-func int nn-freemsg ((msg void*)) "nn_freemsg")

 (define-ftype nn-iovec







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
>







343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382

383
384
385
386
387
388
389
390
 ;;     (let ([c (ftype-ref char () fptr i)])
 ;;       (if (or (char=? c #\nul) (and bytes (>= (+ 1 i) (car bytes))))
 ;; 	   (make-string i)
 ;; 	   (let ([str (f (fx+ i 1))])
 ;; 	     (string-set! str i c)
 ;; 	     str)))))

 (define nn-recv
   (case-lambda
     [(s flags)
      (define b #f)
      (define r #f)
      (dynamic-wind 
	(lambda ()
	  (set! b (make-ftype-pointer void* (foreign-alloc (ftype-sizeof void*))))
	  (set! r (nn-recv% s (ftype-pointer-address b) NN_MSG flags)))
	(lambda ()
	  (if (and r (> r 0))
	      (let ([c (make-ftype-pointer char (ftype-ref void* () b))])
		(char*->bytevector c r))))
	(lambda ()
	  (if (and r (> r 0))
	      (nn-freemsg (ftype-ref void* () b)))
	  (if b (foreign-free (ftype-pointer-address b)))))]
     [(s buf len flags)
      (define b #f)
      (define r #f)
      (dynamic-wind 
	(lambda ()
	  (set! b (make-ftype-pointer void* (foreign-alloc (ftype-sizeof void*))))
	  (set! r (nn-recv% s (ftype-pointer-address b) len flags)))
	(lambda ()
	  (if (and r (> r 0))
	      (let ([c (make-ftype-pointer char (ftype-ref void* () b))])
		(set-box! buf (char*->bytevector c r)))
	      (set-box! buf #f)))
	(lambda ()
	  (if (and r (> r 0))
	      (nn-freemsg (ftype-ref void* () b)))
	  (if b (foreign-free (ftype-pointer-address b)))))

      r]))

 (define-nn-func int nn-sendmsg ((s int) (msghdr (* nn-msghdr)) (flags int))
   "nn_sendmsg")

 (define-nn-func int nn-freemsg ((msg void*)) "nn_freemsg")

 (define-ftype nn-iovec