interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / seed / host / tests / peername.om

93 lines · 2392 bytes Raw Blame History
1note Real TCP loopback endpoints; no external address, proxy claims or policy activation.
2text ok "PASS native peername: accepted peer, truncation, empty slices, errno and bounds\n"
3global server uchar 16
4global client uchar 16
5global output uchar 32
6global pipes uchar 8
7global mode uchar 1
8fn pcheck yes bool to void
9if not yes
10exit 1
11end
12end
13fn pfd off ulong to int
14a = uint get pipes off
15b = shl uint get pipes add off 1 8
16c = shl uint get pipes add off 2 16
17d = shl uint get pipes add off 3 24
18ret int or or or a b c d
19end
20fn main to int
21if eq argcnt 2
22r = argread 1 mode 0 1
23if eq get mode 0 49
24ret int peername neg int 1 output 33 0
25end
26if eq get mode 0 50
27ret int peername neg int 1 output 31 2
28end
29if eq get mode 0 51
30ret int peername neg int 1 output 18446744073709551615 1
31end
32end
33put server 0 2
34put server 4 127
35put server 7 1
36listener = socknew 2 1 0
37pcheck ge listener 0
38pcheck eq bind int listener server 0 16 0
39pcheck eq sockname int listener server 0 16 16
40pcheck eq listen int listener 1 0
41pcheck eq peername int listener output 0 32 neg long 107
42local = socknew 2 1 0
43pcheck ge local 0
44pcheck eq peername int local output 0 32 neg long 107
45pcheck eq connect int local server 0 16 0
46pcheck eq sockname int local client 0 16 16
47pcheck eq waitio int listener 1 1000000000 1
48remote = accept int listener 0
49pcheck ge remote 0
50for i ulong 32
51put output i 165
52end
53pcheck eq peername int remote output 3 16 16
54for i ulong 16
55pcheck eq get output add i 3 get client i
56end
57pcheck eq get output 2 165
58pcheck eq get output 19 165
59if eq get output 5 get server 2
60pcheck ne get output 6 get server 3
61end
62for i ulong 32
63put output i 165
64end
65pcheck eq peername int remote output 4 3 16
66for i ulong 3
67pcheck eq get output add i 4 get client i
68end
69pcheck eq get output 3 165
70pcheck eq get output 7 165
71for i ulong 32
72put output i 165
73end
74pcheck eq peername int remote output 0 0 16
75pcheck eq peername int remote output 32 0 16
76for i ulong 32
77pcheck eq get output i 165
78end
79pcheck eq pipefds pipes 0 8 0 0
80pipefd = pfd 0
81pcheck eq peername pipefd output 0 32 neg long 88
82pcheck eq fclose pipefd 0
83pipefd = pfd 4
84pcheck eq fclose pipefd 0
85pcheck eq fclose int remote 0
86pcheck eq peername int remote output 0 32 neg long 9
87pcheck eq peername neg int 1 output 0 32 neg long 9
88pcheck eq fclose int local 0
89pcheck eq fclose int listener 0
90r = write 1 ok 0 len ok
91pcheck eq r long len ok
92ret 0
93end