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 ;
8 TUPLE: rpc-request args vocabspec wordname ;
10 : send-with-check ( message -- reply/* )
11 serialize flush deserialize dup no-vocab? [ throw ] when ;
13 :: define-remote ( str effect addrspec vocabspec -- )
14 str create-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 ;
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
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 ;