Inferno Contribution: services

Examples of Inferno Services in Limbo

These two examples from Roger Peppe illustrate two ways to write a Limbo program to implement a service.

server.b

The first example, server.b, uses the file2chan system call to provide an append-only file service (on /chan/srvfile). Any data written to the file by another process is received by the server program and is appended to a string held internally. If a process reads the file, the server returns the contents of the string.

To test the program, compile it, start it off in the background, echo a couple of strings to /chan/srvfile and then read the file back again:

% limbo server.b
% server &
% echo hello > /chan/srvfile
% echo goodbyte > /chan/srvfile
% cat /chan/srvfile
hello
goodbye
%

server2.b

This program shows how to implement a similar append-only file service using styxlib to process Styx messages directly.

To test the program, create a temporary directory, echo a couple of strings to the server file and then read the file back again:

% limbo server2.b
% mkdir /tmp/chan
% server2 /tmp/chan
% echo hello > /tmp/chan/srvfile
% echo goodbyte > /tmp/chan/srvfile
% cat /tmp/chan/srvfile
hello
goodbye
%

The following files are available for downloading:
server.b (1236 bytes)
server2.b (4015 bytes)