When a read or write request arrives, it is added to a list of currently outstanding tags maintained by file2chan. If the request is not replied to or acknowledged by the time the invoked command has finished, then a reply will be made automatically (the default is to accept all writes and to give an error on all reads). Each tag is assigned a unique tag id which is stored in the environment variable $tag for the duration of the invoked command. Most commands take an optional tag argument which should be the tag id of a currently outstanding request; if omitted, the value of $tag will be used. The following commands are provided to reply to requests and obtain information about requests:
file2chan /tmp/memfile {rreadone $data} {data = ${rget data}}It is, however, very limited, as binary data stored in the file will be corrupted, and the size of the file is limited to the amount of data that can be transmitted in a single Styx message (8192 bytes).
The following code implements a single-threaded logfile which can support multiple concurrent writers:
{file2chan /chan/log {} {fetchwdata}} >> /tmp/logfile
The following code makes the command cmd available to external programs, and defines a shell function to use it. Note that there's an approximate 8K limit on the size of the argument list that can be passed in this way.
load std file2chan /chan/cmdchan {} {cmd ${unquote ${rget data}}} fn runcmd {echo -n ${quote $*} > /chan/cmdchan}
SH-FILE2CHAN(1 ) | Rev: Thu Feb 15 14:42:47 GMT 2007 |