summaryrefslogtreecommitdiff
path: root/appl/grid/lib/announce.b
blob: 54438b59c6b0238bd32632e03fa59c4ea29cc6c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
implement Announce;
include "sys.m";
	sys:	Sys;
include "dial.m";
	dial: Dial;
include "grid/announce.m";

init()
{
	sys = load Sys Sys->PATH;
}

announce(): (string, ref Sys->Connection)
{
	sysname := readfile("/dev/sysname");
	c := dial->announce("tcp!*!0");
	if(c == nil)
		return (nil, nil);
	local := readfile(c.dir + "/local");
	if(local == nil)
		return (nil, nil);
	for(i := len local - 1; i >= 0; i--)
		if(local[i] == '!')
			break;
	port := local[i+1:];
	if(port == nil)
		return (nil, nil);
	if(port[len port - 1] == '\n')
		port = port[0:len port - 1];
	return ("tcp!" + sysname + "!" + port, c);
}


readfile(f: string): string
{
	fd := sys->open(f, Sys->OREAD);
	if (fd == nil)
		return nil;
	buf := array[8192] of byte;
	n := sys->read(fd, buf, len buf);
	if (n <= 0)
		return nil;
	return string buf[0:n];
}