]> gitweb.factorcode.org Git - factor.git/blob - unmaintained/modules/rpc/rpc.factor
tools.test: Make the flag public. Finish porting tester changes to fuzzer.
[factor.git] / unmaintained / modules / rpc / rpc.factor
1 ! Copyright (C) 2009 Sam Anklesaria.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs fry generalizations io.encodings.binary
4 io.sockets kernel locals namespaces parser sequences serialize
5 vocabs vocabs.parser words io ;
6 IN: modules.rpc
7
8 TUPLE: rpc-request args vocabspec wordname ;
9
10 : send-with-check ( message -- reply/* )
11     serialize flush deserialize dup no-vocab? [ throw ] when ;
12
13 :: define-remote ( str effect addrspec vocabspec -- )
14     str create-word-in effect [ in>> length ] [ out>> length ] bi
15     '[ _ narray vocabspec str rpc-request boa addrspec 9012 <inet> binary
16     [ "doer" serialize send-with-check ] with-client _ firstn ]
17     effect define-declared ;
18
19 :: remote-vocab ( addrspec vocabspec -- vocab )
20    vocabspec "-remote" append dup vocab [ dup set-current-vocab
21      vocabspec addrspec 9012 <inet> binary [ "getter" serialize send-with-check ] with-client
22      [ first2 addrspec vocabspec define-remote ] each
23    ] unless ;
24
25 : remote-load ( addr vocabspec -- voabspec ) [ swap
26     9012 <inet> binary [ "loader" serialize serialize flush deserialize ] with-client ] keep
27     [ dictionary get-global set-at ] keep ;