Check-in [4228556d4b]
Not logged in

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

Overview
Comment:added nanomsg repl example
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 4228556d4bbb9009114009274b0597d61653c5e6
User & Date: ovenpasta@pizzahack.eu 2016-08-17 11:49:37
Context
2016-09-01
08:27
various improvements, added lmdb , added license notices check-in: 112a40d018 user: ovenpasta@pizzahack.eu tags: trunk
2016-08-17
11:49
added nanomsg repl example check-in: 4228556d4b user: ovenpasta@pizzahack.eu tags: trunk
10:43
fixed small bug in nn-recv check-in: 1e3d1ba295 user: ovenpasta@pizzahack.eu tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added nanomsg/local-repl.





















































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#! /usr/bin/env scheme-script
; -*- mode: scheme -*-
;
; example of remote REPL
; you can use any transport, tcp:// ipc:// websocket inproc
; see http://nanomsg.org/v1.0.0/nanomsg.7.html
; and nanomsg.sls for details
;
; ./local-repl tcp://127.0.0.1:12345
; ABC
;
; meanwhile in another terminal...
; ./remote-repl tcp://127.0.0.1:12345
; > (+ 1 2)
; 3
; > (printf "ABC~n") --> will print ABC on the local repl process
;
; The nice thing is that you can scale to any protocol and
; that it can be integrated in an event/main loop
; it uses non-blocking (read) and you invoke (my-local-repl) until => #f
;
; TODO: add a command for local exit. #!eof object will only close the remote 
; connection....

#!chezscheme

(import (chezscheme) (nanomsg))
(nanomsg-library-init)

(define argv (command-line-arguments))

(define sock (nn-socket AF_SP NN_REP))
(define eid (nn-bind sock (car argv)))

(define (my-local-repl)
  (call/cc 
   (lambda (return)
     (let* ([buf (box #t)]
	    [r (nn-recv sock buf NN_MSG NN_DONTWAIT)])
       (when r
	     (guard (e [else (printf "error in eval ~d~n" e)])
		    (with-input-from-string (utf8->string (unbox buf))
		      (lambda ()
			(let ([pr (call-with-string-output-port
				   (lambda (p)
				     (let ([token (read)])
				       (if #f;(eof-object? token) 
					   (return #f)
					   (pretty-print 
					    (eval token 
						  (interaction-environment)) p)))))])
			  (nn-send sock (string->utf8 pr) 0)))))))
     #t)))

(let loop () 
  (when (my-local-repl)
	(sleep (make-time 'time-duration 1000000 0))
	(loop)))

Added nanomsg/remote-repl.

































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#! /usr/bin/env scheme-script
; -*- mode: scheme -*-
; example of remote REPL
; you can use any transport, tcp:// ipc:// websocket inproc
; see http://nanomsg.org/v1.0.0/nanomsg.7.html
; and nanomsg.sls for details
;
; ./local-repl tcp://127.0.0.1:12345
; ABC
;
; meanwhile in another terminal...
; ./remote-repl tcp://127.0.0.1:12345
; > (+ 1 2)
; 3
; > (printf "ABC~n") --> will print ABC on the local repl process
;
; The nice thing is that you can scale to any protocol and
; that it can be integrated in an event/main loop
; it uses non-blocking (read) and you invoke (my-local-repl) until => #f
;
; TODO: add a command for local exit. #!eof object will only close the remote 
; connection....

#!chezscheme

(import (chezscheme) (nanomsg))
(nanomsg-library-init)

(define argv (command-line-arguments))

(define sock (nn-socket AF_SP NN_REQ))
(define eid (nn-connect sock (car argv)))

(call/cc 
 (lambda (return)
   (let loop ()
     (printf "> ")
     (nn-send sock (string->utf8 
		    (call-with-string-output-port
		     (lambda (p)
		       (let ([token (read)])
			 (if (eof-object? token)
			     (return #f)
			     (write token p)))))) 0)
     (let ([buf (box #t)])
       (nn-recv sock buf NN_MSG 0)
       (printf "~d" (utf8->string (unbox buf))))
     (loop))))