Service provided:
snap
Client of service:
image (vc-image.setl, Section A.20 [vc-image.setl])
Called by parent program:
vc-toplev.setl (Section A.42 [vc-toplev.setl])
Textually #includes:
vc-exit.setl (Section A.15 [vc-exit.setl])
vc-getname.setl (Section A.16 [vc-getname.setl])
vc-msg.setl (Section A.30 [vc-msg.setl])
vc-obtain.setl (Section A.31 [vc-obtain.setl])
vc-provide.setl (Section A.32 [vc-provide.setl])
webutil.setl (Section A.44 [webutil.setl])
Source code: *
const yhwh = `vc-snap.setl';
-- This server sends a single HTTP-wrapped JPEG image, then closes.
const sigterm_fd = open (`SIGTERM', `signal'); -- catch TERM signals
const snap_fd = fileno provide_service (`snap');
var clients := {};
loop
[ready] := select ([{sigterm_fd, snap_fd} + domain clients]);
if sigterm_fd in ready then
msg (yhwh + ` (' + str pid + `) caught SIGTERM');
quit_gracefully;
end if;
for client = clients(pump_fd) | pump_fd in ready loop
done_client (pump_fd);
end loop;
if snap_fd in ready then
fd := accept (snap_fd);
if fdom then
name := getname fd;
pump_fd := pump();
if pump_fd = -1 then
-- child
[uri, protocol, mime_headers] := get_request (fd);
mu := massage_uri uri ? {};
-- We ignore all details of the GET or POST request.
image_fd := fileno obtain_service (`image');
printa (image_fd, `JPEG');
reada (image_fd, n);
image := getn (image_fd, n);
assert #image = n;
printa (fd, `HTTP/1.0 200 OK');
printa (fd, `Server: WEBeye');
printa (fd, `Content-type: image/jpeg');
printa (fd, `Content-length: '+str n);
printa (fd, `Pragma: no-cache');
printa (fd, `Expires: 0');
printa (fd, `');
putc (fd, image);
stop;
end if;
close (fd); -- child hangs onto this
client := {};
client.name := name;
clients(pump_fd) := client;
end if;
end if;
end loop;
proc done_client (pump_fd);
close (pump_fd);
clients(pump_fd) := om;
end proc done_client;
proc quit_gracefully;
exit_gracefully ([[`pump for client ' + client.name, pump_fd] :
client = clients(pump_fd)]);
end proc;
#include ``vc-provide.setl''
#include ``vc-obtain.setl''
#include ``vc-getname.setl''
#include ``vc-exit.setl''
#include ``vc-msg.setl''
#include ``webutil.setl''