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 / protocol / omnet / cmd / tkad / socket.om

134 lines · 1981 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2text ds_sock "tkad.sock"
3fn dsio fd int b edit uchar 65536 n ulong output ulong to int
4p = ulong 0
5deadline = add monons 3000000000
6r = long 0
7while lt p n bound 65537
8left = sub deadline monons
9if le left 0
10ret 1
11end
12if eq output 0
13r = waitio fd 1 left
14else
15r = waitio fd 4 left
16end
17if lt r 0
18if eq r -4
19continue
20end
21ret 1
22end
23if eq r 0
24ret 1
25end
26if eq output 0
27r = recv fd b p sub n p int 0
28else
29r = send fd b p sub n p int 0
30end
31if or eq r -11 eq r -4
32continue
33end
34if le r 0
35ret 1
36end
37p = add p ulong r
38end
39ret 0
40end
41fn dsclient fd int to void
42h = new uchar 65536 0
43b = new uchar 65536 0
44o = new uchar 65536 0
45if ne dsio fd h 20 0 0
46ret
47end
48if or ne get h 0 84 ne get h 1 75
49ret
50end
51if or ne get h 2 65 ne get h 3 1
52ret
53end
54if gt get h 5 1
55ret
56end
57if or ne get h 6 0 ne get h 7 0
58ret
59end
60n = ulong 0
61for i ulong 4
62n = or n shl ulong get h add i 16 mul i 8
63end
64if gt n 65536
65ret
66end
67put ds_ctl 4 ulong get h 4
68put ds_ctl 3 ulong get h 5
69put ds_ctl 2 dsleget h 8
70if ne dsio fd b n 0 0
71ret
72end
73z = dsrequest b n o
74put h 4 uchar and z 255
75put h 5 uchar shr z 8
76put h 6 0
77put h 7 0
78n = get ds_ctl 6
79for i ulong 4
80put h add i 8 uchar and shr n mul i 8 255
81end
82if ne dsio fd h 12 1 0
83ret
84end
85z = dsio fd o n 1
86end
87fn dslisten to int
88z = unlink ds_sock 0 len ds_sock
89if and ne z 0 ne z -2
90ret -1
91end
92addr = new uchar 128 0
93put addr 0 1
94for i ulong len ds_sock
95put addr add i 2 get ds_sock i
96end
97fd = socknew int 1 int 526337 int 0
98if lt fd 0
99ret -1
100end
101if ne bind int fd addr 0 add len ds_sock 3 0
102z = fclose int fd
103ret -1
104end
105if ne chmod ds_sock 0 len ds_sock int 384 0
106z = fclose int fd
107ret -1
108end
109if ne listen int fd int 32 0
110z = fclose int fd
111ret -1
112end
113ret int fd
114end
115fn dsbatch fd int to void
116for i ulong 100000
117r = waitio fd int 1 long -1
118if lt r 0
119if eq r -4
120continue
121end
122exit 75
123end
124client = accept fd int 526336
125if lt client 0
126if or eq client -11 eq client -4
127continue
128end
129exit 75
130end
131dsclient int client
132z = fclose int client
133end
134end