forked from ovenpasta/thunderchez
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipeline
executable file
·51 lines (38 loc) · 1.27 KB
/
pipeline
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
#! /usr/bin/env scheme-script
; -*- mode: scheme -*-
; Getting Started with 'nanomsg'
; Pipeline (A One-Way Pipe)
; from https://github.com/dysinger/nanomsg-examples#pipeline
#!chezscheme
(import (nanomsg) (chezscheme))
(nanomsg-library-init)
(define node0-name "node0")
(define node1-name "node1")
(define (node0 url)
(define sock (nn-socket AF_SP NN_PULL))
(nn-bind sock url)
(let loop ()
(let ([buf (box #t)])
(define bytes (nn-recv sock buf NN_MSG 0))
(printf "NODE0: RECEIVED '~d'~n" (utf8->string (unbox buf))))
(loop)))
(define (node1 url msg)
(define sock (nn-socket AF_SP NN_PUSH))
(define eid (nn-connect sock url))
(printf "NODE1: SENDING '~d'~n" msg)
(let ([bytes (nn-send sock (string->utf8 msg) 0)])
(nn-shutdown sock eid)))
(define argv (command-line-arguments))
(define argc (length argv))
(cond
[(and (> argc 1) (string=? node0-name (car argv)))
(node0 (cadr argv))]
[(and (> argc 2) (string=? node1-name (car argv)))
(node1 (cadr argv) (caddr argv))]
[else
(printf "Usage: pipeline ~d|~d <URL> <ARG> ...'~n" node0-name node1-name)])
#!eof
./pipeline node0 ipc:///tmp/pipeline.ipc & node0=$! && sleep 1
./pipeline node1 ipc:///tmp/pipeline.ipc "Hello, World!"
./pipeline node1 ipc:///tmp/pipeline.ipc "Goodbye."
kill $node0