factor/unmaintained/modules/rpc/rpc.factor

27 lines
1.1 KiB
Factor
Raw Normal View History

2009-07-30 18:12:49 -04:00
! Copyright (C) 2009 Sam Anklesaria.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors assocs fry generalizations io.encodings.binary
io.sockets kernel locals namespaces parser sequences serialize
2009-08-04 00:12:34 -04:00
vocabs vocabs.parser words io ;
2009-07-29 16:48:54 -04:00
IN: modules.rpc
TUPLE: rpc-request args vocabspec wordname ;
: send-with-check ( message -- reply/* )
serialize flush deserialize dup no-vocab? [ throw ] when ;
2009-07-29 16:48:54 -04:00
:: define-remote ( str effect addrspec vocabspec -- )
str create-in effect [ in>> length ] [ out>> length ] bi
'[ _ narray vocabspec str rpc-request boa addrspec 9012 <inet> binary
2009-08-04 00:12:34 -04:00
[ "doer" serialize send-with-check ] with-client _ firstn ]
2009-07-29 16:48:54 -04:00
effect define-declared ;
:: remote-vocab ( addrspec vocabspec -- vocab )
vocabspec "-remote" append dup vocab [ dup set-current-vocab
vocabspec addrspec 9012 <inet> binary [ "getter" serialize send-with-check ] with-client
2009-07-29 16:48:54 -04:00
[ first2 addrspec vocabspec define-remote ] each
] unless ;
: remote-load ( addr vocabspec -- voabspec ) [ swap
9012 <inet> binary [ "loader" serialize serialize flush deserialize ] with-client ] keep
[ dictionary get-global set-at ] keep ;