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 / net / tests / live.om

981 lines · 17863 bytes Raw Blame History
1note seed/net/tests/live.om -- loopback socket tests for seed/net/http.om, run by check.py.
2note Compose: { printf 'om2\n'; cat seed/net/http.om seed/net/tests/live.om; } | omc
3note Every socket is 127.0.0.1 with an ephemeral port chosen by the kernel (bind port 0); the
4note server side is a forked child. No fixed port, no outside traffic, never port 18091.
5note Exit 0 = every check passed; any other status names the first failed check (see the
6note `ret` numbers below; 100+ are traps). The parent reaps every child it forks.
7text tsum "/sum"
8text tblob "/blob"
9text tblobc "/blobc"
10text tevts "/events"
11text tquit "/quit"
12text tslash "/"
13text tpost "POST"
14text tget "GET"
15text thead "HEAD"
16text thost "Host"
17text thval "127.0.0.1"
18text texp "Expect"
19text tcont "100-continue"
20text tctype "Content-Type"
21text tplain "text/plain"
22text ttick "tick"
23text tkal "keepalive"
24text tretry "1500"
25text tsec "\nsecond"
26text tthird "third"
27text tpfd "/proc/self/fd"
28text tpart "GET / HTTP/1.1\n"
29text tpipe "GET /blob HTTP/1.1\nHost: a\n\nHEAD /blob HTTP/1.1\nHost: a\n\n"
30text tm1 "GET / HTTP/1.1\nHost: a\nBad Header: x\n\n"
31text tm2 "POST / HTTP/1.1\nHost: a\nContent-Length: 3\nTransfer-Encoding: chunked\n\n"
32text tm3 "POST / HTTP/1.1\nHost: a\nTransfer-Encoding: gzip\n\n"
33text tm4 "GET / HTTP/2.0\nHost: a\n\n"
34text tm5 "GET / HTTP/1.1\n\n"
35text tm6 "GET / HTTP/1.1\nHost: a\nX: 1\n folded\n\n"
36text tm7 "POST / HTTP/1.1\nHost: a\nContent-Length: 5\nContent-Length: 5\n\n"
37text tm8 "GET / HTTP/1.1\nHost: a\nExpect: something\n\n"
38text tearly "/early"
39text tone "x"
40text thello "hello"
41text tbodyp "POST /sum HTTP/1.1\nHost: a\nContent-Length: 10\n\n"
42text tearlyq "POST /early HTTP/1.1\nHost: a\nExpect: 100-continue\nContent-Length: 5\n\nhello"
43text tsmug "helloGET /admin HTTP/1.1\nHost: x\n\n"
44note ======== helpers
45fn pval j ulong to uchar
46ret uchar rem add mul j 7 3 251
47end
48fn pfill b edit uchar * n ulong to void
49for k ulong 64
50s = mul k 65536
51if ge s n
52break
53end
54m = hmin sub n s 65536
55for i ulong m
56j = add s i
57put b j pval j
58end
59end
60end
61fn pcheck b view uchar * n ulong to bool
62if ne len b n
63ret false
64end
65for k ulong 64
66s = mul k 65536
67if ge s n
68ret true
69end
70m = hmin sub n s 65536
71for i ulong m
72if ne get b add s i pval add s i
73ret false
74end
75end
76end
77ret true
78end
79fn fnvbig a view uchar * to ulong
80h = ulong 14695981039346656037
81n = len a
82for k ulong 64
83s = mul k 65536
84if ge s n
85ret h
86end
87m = hmin sub n s 65536
88for i ulong m
89h = mul xor h ulong get a add s i 1099511628211
90end
91end
92ret h
93end
94note ddecat: decimal v at b[p, ...); the end index
95fn ddecat b edit uchar * p ulong v ulong to ulong
96d = new uchar 20 0
97i = ulong 20
98x = v
99for it ulong 20
100i = sub i 1
101put d i uchar add rem x 10 48
102x = div x 10
103if eq x 0
104break
105end
106end
107q = p
108for k ulong sub 20 i
109put b q get d add i k
110q = add q 1
111end
112ret q
113end
114fn appt b edit uchar * p ulong t view uchar * to ulong
115for i ulong len t
116put b add p i get t i
117end
118ret add p len t
119end
120note obh: 16 hex digits of h, SP, decimal n; the length
121fn obh o edit uchar 64 h ulong n ulong to ulong
122for k ulong 16
123put o k hhexd and shr h mul sub 15 k 4 15
124end
125put o 16 32
126ret ddecat o 17 n
127end
128note evgen: SSE event i data; raw selects the CRLF line break the server sends, decoded form uses LF
129fn evgen b edit uchar 64 i ulong raw bool to ulong
130put b 0 101
131put b 1 118
132put b 2 45
133p = ddecat b 3 i
134if ne rem i 5 0
135ret p
136end
137p = appt b p tsec
138if raw
139put b p 13
140p = add p 1
141end
142put b p 10
143p = add p 1
144ret appt b p tthird
145end
146fn mklisten a edit uchar 16 to int
147r = haddr4 a 2130706433 0
148if lt r 0
149ret -1
150end
151fd = hlisten a 16
152if lt fd 0
153ret -1
154end
155ret int fd
156end
157note fdcount: open descriptors of this process (entries of /proc/self/fd, minus the one used)
158fn fdcount buf edit uchar 4096 to long
159fd = fopen tpfd 0 len tpfd 16384 0
160if lt fd 0
161ret -1
162end
163n = long 0
164for it ulong 1000
165k = getdnts int fd buf 0 len buf
166if le k 0
167break
168end
169p = ulong 0
170while lt p ulong k bound 4096
171rl = or ulong get buf add p 16 shl ulong get buf add p 17 8
172if ne get buf add p 19 46
173n = add n 1
174end
175p = add p rl
176end
177end
178c = fclose int fd
179ret sub n 1
180end
181note rawsend: t with every LF sent as CRLF (lets tests send malformed heads)
182fn rawsend cs edit ulong 320 io edit uchar 131072 t view uchar * to long
183hwreset cs
184r = long 0
185for i ulong len t
186c = get t i
187if eq c 10
188r = hfe r hputb cs io 13
189end
190r = hfe r hputb cs io c
191end
192ret hfe r hflush cs io
193end
194fn waitok pid long to int
195st = new uchar 4 0
196r = waitpid int pid st 0 4 0
197if ne r pid
198ret 90
199end
200if ne get st 0 0
201ret 91
202end
203ret int get st 1
204end
205note ======== server (child process)
206fn obsum cs edit ulong 320 io edit uchar 131072 o edit uchar 64 k ulong to long
207r = hrspst cs io 200
208r = hfe r hhname cs io tctype
209r = hfe r hhval cs io tplain
210r = hfe r hhend cs io 0 k
211r = hfe r hput cs io view part o 0 k
212ret hfe r hwfin cs io
213end
214fn rsum cs edit ulong 320 io edit uchar 131072 bg edit uchar 1048592 to long
215o = new uchar 64 0
216put cs HBCAP 1048576
217n = hbodyall cs io bg
218if lt n 0
219if eq n HEBIG
220ret hrsperr cs io 413
221end
222ret hrsperr cs io 400
223end
224h = fnvbig view part bg 0 ulong n
225k = obh o h ulong n
226ret obsum cs io o k
227end
228fn rblob cs edit ulong 320 io edit uchar 131072 bg edit uchar 1048592 to long
229pfill bg 307200
230r = hrspst cs io 200
231r = hfe r hhend cs io 0 307200
232r = hfe r hput cs io view part bg 0 307200
233ret hfe r hwfin cs io
234end
235fn rblobc cs edit ulong 320 io edit uchar 131072 bg edit uchar 1048592 to long
236pfill bg 307200
237r = hrspst cs io 200
238r = hfe r hhend cs io 1 0
239for k ulong 308
240s = mul k 1000
241if ge s 307200
242break
243end
244r = hfe r hput cs io view part bg s hmin 1000 sub 307200 s
245end
246ret hfe r hwfin cs io
247end
248fn revts cs edit ulong 320 io edit uchar 131072 to long
249b = new uchar 64 0
250d = new uchar 20 0
251r = hrspsse cs io
252if lt r 0
253ret r
254end
255for i ulong 40
256if eq i 3
257r = hfe r hssecmt cs io tkal
258end
259if eq i 7
260r = hfe r hsseret cs io tretry
261end
262if eq rem i 2 1
263r = hfe r hsseevt cs io ttick
264end
265k = ddecat d 0 i
266r = hfe r hsseid cs io view part d 0 k
267k = evgen b i true
268r = hfe r hssedat cs io view part b 0 k
269r = hfe r hsseend cs io
270if lt r 0
271ret r
272end
273end
274ret hwfin cs io
275end
276fn rearly cs edit ulong 320 io edit uchar 131072 to long
277d = new uchar 16 0
278put cs HKEEP 0
279r = hrspst cs io 200
280r = hfe r hhend cs io 0 5
281r = hfe r hput cs io thello
282r = hfe r hflush cs io
283b = hbodyall cs io d
284if ne b 5
285ret -1
286end
287ret hfe r hwfin cs io
288end
289note route: 0 = served, 1 = quit, negative = I/O failure
290fn route cs edit ulong 320 io edit uchar 131072 bg edit uchar 1048592 to long
291if and hismeth cs io tpost hispath cs io tsum
292ret rsum cs io bg
293end
294if hispath cs io tblob
295ret rblob cs io bg
296end
297if hispath cs io tblobc
298ret rblobc cs io bg
299end
300if hispath cs io tevts
301ret revts cs io
302end
303if hispath cs io tearly
304ret rearly cs io
305end
306if hispath cs io tquit
307r = hrsperr cs io 200
308ret 1
309end
310ret hrsperr cs io 404
311end
312fn srvconn lf int cs edit ulong 320 io edit uchar 131072 bg edit uchar 1048592 to long
313c = haccept lf 10000000000
314if lt c 0
315ret 40
316end
317r = hinit cs io int c 1
318if lt r 0
319ret 41
320end
321hsettmo cs 3000000000 3000000000
322q = long 0
323for k ulong 16
324r = hreqrd cs io
325if le r 0
326if lt r 0
327x = hreject cs io r
328end
329break
330end
331r = route cs io bg
332if lt r 0
333q = 42
334break
335end
336if eq r 1
337q = 1
338break
339end
340if eq hnext cs io 0
341break
342end
343end
344r = hclose cs
345ret q
346end
347fn srvmain lf int cs edit ulong 320 io edit uchar 131072 bg edit uchar 1048592 to int
348for j ulong 64
349r = srvconn lf cs io bg
350if eq r 1
351ret 0
352end
353if ne r 0
354ret int r
355end
356end
357ret 43
358end
359note ======== client (parent process)
360fn cdial cs edit ulong 320 io edit uchar 131072 a view uchar 16 to long
361fd = hdial a 2000000000
362if lt fd 0
363ret fd
364end
365r = hinit cs io int fd 0
366hsettmo cs 5000000000 5000000000
367ret r
368end
369fn creq cs edit ulong 320 io edit uchar 131072 m view uchar * pa view uchar * to long
370r = hreqst cs io m
371r = hfe r hreqtg cs io pa
372r = hfe r hhname cs io thost
373r = hfe r hhval cs io thval
374r = hfe r hhend cs io 0 0
375r = hfe r hwfin cs io
376if lt r 0
377ret r
378end
379ret hrsprd cs io
380end
381note csum: POST /sum with n pattern bytes (chunked or Content-Length); the server's hash must match
382fn csend cs edit ulong 320 io edit uchar 131072 bg edit uchar 1048592 n ulong ch bool to long
383r = hreqst cs io tpost
384r = hfe r hreqtg cs io tsum
385r = hfe r hhname cs io thost
386r = hfe r hhval cs io thval
387if ch
388r = hfe r hhend cs io 1 0
389for k ulong 512
390s = mul k 4096
391if ge s n
392break
393end
394r = hfe r hput cs io view part bg s hmin 4096 sub n s
395end
396else
397r = hfe r hhend cs io 0 n
398r = hfe r hput cs io view part bg 0 n
399end
400r = hfe r hwfin cs io
401if lt r 0
402ret r
403end
404ret hrsprd cs io
405end
406fn csum cs edit ulong 320 io edit uchar 131072 bg edit uchar 1048592 n ulong ch bool to int
407o = new uchar 64 0
408w = new uchar 64 0
409pfill bg n
410k = obh w fnvbig view part bg 0 n n
411st = csend cs io bg n ch
412if ne st 200
413ret 10
414end
415g = hbodyall cs io o
416if ne g long k
417ret 11
418end
419for i ulong k
420if ne get o i get w i
421ret 12
422end
423end
424ret 0
425end
426fn cblob cs edit ulong 320 io edit uchar 131072 bg edit uchar 1048592 pa view uchar * to int
427st = creq cs io tget pa
428if ne st 200
429ret 20
430end
431g = hbodyall cs io bg
432if ne g 307200
433ret 21
434end
435if not pcheck view part bg 0 307200 307200
436ret 22
437end
438ret 0
439end
440fn chead cs edit ulong 320 io edit uchar 131072 bg edit uchar 1048592 to int
441st = creq cs io thead tblob
442if ne st 200
443ret 25
444end
445if ne get cs HBMODE 0
446ret 26
447end
448i = hhfind cs io hnclen
449if lt i 0
450ret 27
451end
452if ne hdecv view part io hhvoff cs ulong i hhvlen cs ulong i 307200
453ret 28
454end
455g = hbodyall cs io bg
456if ne g 0
457ret 29
458end
459ret 0
460end
461note chkev: event i as decoded by the reader
462fn chkev ss edit ulong 16 lb edit uchar 4096 eb edit uchar 64 i ulong to long
463k = evgen eb i false
464if ne get ss HSDLEN k
465ret -70
466end
467for j ulong k
468if ne get lb add 128 j get eb j
469ret -71
470end
471end
472if eq rem i 2 1
473if ne get ss HSELEN 4
474ret -72
475end
476if not heq view part lb 0 4 ttick
477ret -73
478end
479else
480if ne get ss HSELEN 0
481ret -74
482end
483end
484k = ddecat eb 0 i
485if ne get ss HSILEN k
486ret -75
487end
488for j ulong k
489if ne get lb add 64 j get eb j
490ret -76
491end
492end
493if and ge i 7 ne get ss HSRETRY 1500
494ret -77
495end
496ret 0
497end
498note cfeed: feed src to the reader, checking every completed event; the new event count
499fn cfeed ss edit ulong 16 lb edit uchar 4096 src view uchar * nev ulong to long
500eb = new uchar 64 0
501off = ulong 0
502v = nev
503for j ulong 1000
504if ge off len src
505ret long v
506end
507c = hssefeed ss lb view part src off sub len src off
508if lt c 0
509ret -63
510end
511off = add off ulong c
512if ne get ss HSRDY 0
513e = chkev ss lb eb v
514if lt e 0
515ret e
516end
517v = add v 1
518hssenext ss
519end
520end
521ret -64
522end
523fn csse cs edit ulong 320 io edit uchar 131072 bg edit uchar 1048592 to int
524ss = new ulong 16 0
525lb = new uchar 4096 0
526r = hsseinit ss
527st = creq cs io tget tevts
528if ne st 200
529ret 60
530end
531if ne get cs HBMODE 2
532ret 61
533end
534nev = ulong 0
535for it ulong 1000000
536n = hbodyrd cs io part bg 0 7
537if lt n 0
538ret 62
539end
540if eq n 0
541break
542end
543v = cfeed ss lb view part bg 0 ulong n nev
544if lt v 0
545ret int neg v
546end
547nev = ulong v
548end
549if ne nev 40
550ret 65
551end
552ret 0
553end
554fn cexp cs edit ulong 320 io edit uchar 131072 to int
555r = hreqst cs io tpost
556r = hfe r hreqtg cs io tsum
557r = hfe r hhname cs io thost
558r = hfe r hhval cs io thval
559r = hfe r hhname cs io texp
560r = hfe r hhval cs io tcont
561r = hfe r hhend cs io 0 1048577
562r = hfe r hflush cs io
563if lt r 0
564ret 80
565end
566st = hrsprd cs io
567if ne st 413
568ret 81
569end
570if ne get cs HKEEP 0
571ret 82
572end
573ret 0
574end
575note conn1: one keep-alive connection carrying seven exchanges
576fn conn1 cs edit ulong 320 io edit uchar 131072 bg edit uchar 1048592 a view uchar 16 to int
577if lt cdial cs io a 0
578ret 1
579end
580e = csum cs io bg 307200 false
581if ne e 0
582ret e
583end
584e = csum cs io bg 1048576 true
585if ne e 0
586ret add e 2
587end
588e = cblob cs io bg tblob
589if ne e 0
590ret e
591end
592e = chead cs io bg
593if ne e 0
594ret e
595end
596e = cblob cs io bg tblobc
597if ne e 0
598ret add e 3
599end
600e = csse cs io bg
601if ne e 0
602ret e
603end
604if ne get cs HNMSG 6
605ret 2
606end
607e = cexp cs io
608if ne e 0
609ret e
610end
611r = hclose cs
612ret 0
613end
614note conn2: two pipelined requests sent in one write, answered in order
615fn conn2 cs edit ulong 320 io edit uchar 131072 bg edit uchar 1048592 a view uchar 16 to int
616if lt cdial cs io a 0
617ret 3
618end
619if lt rawsend cs io tpipe 0
620ret 4
621end
622st = hrsprd cs io
623if ne st 200
624ret 5
625end
626g = hbodyall cs io bg
627if ne g 307200
628ret 6
629end
630if not pcheck view part bg 0 307200 307200
631ret 6
632end
633if ne hnext cs io 1
634ret 7
635end
636put cs HISHEAD 1
637st = hrsprd cs io
638if ne st 200
639ret 8
640end
641if ne hbodyall cs io bg 0
642ret 9
643end
644r = hclose cs
645ret 0
646end
647fn cmal cs edit ulong 320 io edit uchar 131072 a view uchar 16 t view uchar * want long to int
648if lt cdial cs io a 0
649ret 30
650end
651if lt rawsend cs io t 0
652ret 31
653end
654st = hrsprd cs io
655kp = get cs HKEEP
656r = hclose cs
657if ne st want
658ret 32
659end
660if ne kp 0
661ret 33
662end
663ret 0
664end
665fn cmals cs edit ulong 320 io edit uchar 131072 a view uchar 16 to int
666e = cmal cs io a tm1 400
667e = add e cmal cs io a tm2 400
668e = add e cmal cs io a tm3 501
669e = add e cmal cs io a tm4 505
670e = add e cmal cs io a tm5 400
671e = add e cmal cs io a tm6 400
672e = add e cmal cs io a tm7 400
673e = add e cmal cs io a tm8 417
674if ne e 0
675ret 34
676end
677ret 0
678end
679note cearly (F3): the handler sends its whole Content-Length response before reading a body sent
680note with Expect: 100-continue; no 100 Continue may follow the final response on the wire
681fn cearly cs edit ulong 320 io edit uchar 131072 a view uchar 16 to int
682d = new uchar 16 0
683if lt cdial cs io a 0
684ret 16
685end
686if lt rawsend cs io tearlyq 0
687ret 16
688end
689st = hrsprd cs io
690if ne st 200
691ret 17
692end
693g = hbodyall cs io d
694if or ne g 5 ne get cs HKEEP 0
695ret 18
696end
697n = get cs HRLEN
698k = long 0
699if gt n get cs HRPOS
700k = long sub n get cs HRPOS
701else
702k = hrecvio cs io n 1
703end
704r = hclose cs
705if ne k 0
706ret 19
707end
708ret 0
709end
710fn cquit cs edit ulong 320 io edit uchar 131072 a view uchar 16 to int
711if lt cdial cs io a 0
712ret 35
713end
714st = creq cs io tget tquit
715r = hclose cs
716if ne st 200
717ret 36
718end
719ret 0
720end
721fn tmain cs edit ulong 320 io edit uchar 131072 bg edit uchar 1048592 to int
722a = new uchar 16 0
723lf = mklisten a
724if lt lf 0
725ret 44
726end
727pid = fork
728if lt pid 0
729ret 45
730end
731if eq pid 0
732exit srvmain lf cs io bg
733end
734c = fclose lf
735e = conn1 cs io bg a
736if eq e 0
737e = conn2 cs io bg a
738end
739if eq e 0
740e = cmals cs io a
741end
742if eq e 0
743e = cearly cs io a
744end
745q = cquit cs io a
746w = waitok pid
747if ne e 0
748ret e
749end
750if ne q 0
751ret q
752end
753ret w
754end
755note ======== deadlines
756note tbody (F1): after a complete head, a client trickles the body one byte per 100 ms, each
757note well inside the 5 s idle limit; the server's 300 ms body deadline must end the read
758fn tbody cs edit ulong 320 io edit uchar 131072 bg edit uchar 1048592 to int
759a = new uchar 16 0
760lf = mklisten a
761if lt lf 0
762ret 46
763end
764pid = fork
765if lt pid 0
766ret 47
767end
768if eq pid 0
769c = fclose lf
770if lt cdial cs io a 0
771exit 1
772end
773r = rawsend cs io tbodyp
774for i ulong 10
775s = sleepns 100000000
776r = send int get cs HFD tone 0 1 0
777end
778r = hclose cs
779exit 0
780end
781c = haccept lf 2000000000
782if lt c 0
783ret 48
784end
785r = hinit cs io int c 1
786hsettmo cs 5000000000 5000000000
787hsetbdl cs 300000000
788r = hreqrd cs io
789t0 = monons
790if eq r 1
791r = hbodyall cs io bg
792end
793dt = sub monons t0
794x = hclose cs
795x = fclose lf
796w = waitok pid
797if ne r HETIME
798ret 49
799end
800if gt dt 1500000000
801ret 98
802end
803ret w
804end
805note tover (F2): a Content-Length body refuses bytes past clen before buffering any of them,
806note in the client role (no smuggled request) and in the server role (memory mode, no I/O)
807fn tover cs edit ulong 320 io edit uchar 131072 to int
808r = hinit cs io -1 0
809r = hreqst cs io tpost
810r = hfe r hreqtg cs io tslash
811r = hfe r hhname cs io thost
812r = hfe r hhval cs io thval
813r = hfe r hhend cs io 0 5
814if lt r 0
815ret 37
816end
817w0 = get cs HWLEN
818if ne hput cs io tsmug HEINVAL
819ret 38
820end
821if or ne get cs HWLEN w0 ne get cs HWOUT 0
822ret 39
823end
824r = hinit cs io -1 1
825r = hrspst cs io 200
826r = hfe r hhend cs io 0 5
827r = hfe r hput cs io thello
828if lt r 0
829ret 97
830end
831w0 = get cs HWLEN
832if ne hputb cs io 33 HEINVAL
833ret 97
834end
835if or ne get cs HWLEN w0 ne get cs HKEEP 0
836ret 97
837end
838ret 0
839end
840note tslow: a client that sends half a head and stalls; the server's 200 ms head deadline fires
841fn tslow cs edit ulong 320 io edit uchar 131072 to int
842a = new uchar 16 0
843lf = mklisten a
844if lt lf 0
845ret 50
846end
847pid = fork
848if lt pid 0
849ret 51
850end
851if eq pid 0
852c = fclose lf
853if lt cdial cs io a 0
854exit 1
855end
856r = rawsend cs io tpart
857s = sleepns 1500000000
858r = hclose cs
859exit 0
860end
861c = haccept lf 2000000000
862if lt c 0
863ret 52
864end
865r = hinit cs io int c 1
866hsettmo cs 5000000000 200000000
867t0 = monons
868r = hreqrd cs io
869dt = sub monons t0
870x = hclose cs
871x = fclose lf
872w = waitok pid
873if ne r HETIME
874ret 53
875end
876if or lt dt 150000000 gt dt 1000000000
877ret 54
878end
879ret w
880end
881note tidle: a server that never answers; the client's 200 ms idle wait fires
882fn tidle cs edit ulong 320 io edit uchar 131072 to int
883a = new uchar 16 0
884lf = mklisten a
885if lt lf 0
886ret 55
887end
888pid = fork
889if lt pid 0
890ret 56
891end
892if eq pid 0
893c = haccept lf 2000000000
894if lt c 0
895exit 1
896end
897r = hinit cs io int c 1
898r = hreqrd cs io
899s = sleepns 1500000000
900r = hclose cs
901exit 0
902end
903x = fclose lf
904if lt cdial cs io a 0
905ret 57
906end
907hsettmo cs 200000000 0
908t0 = monons
909r = creq cs io tget tslash
910dt = sub monons t0
911x = hclose cs
912w = waitok pid
913if ne r HETIME
914ret 58
915end
916if or lt dt 150000000 gt dt 1000000000
917ret 59
918end
919ret w
920end
921note trefuse: a bound but not listening port refuses the connection; nothing leaks
922fn trefuse to int
923a = new uchar 16 0
924r = haddr4 a 2130706433 0
925fd = socknew 2 526337 0
926if lt fd 0
927ret 66
928end
929r = bind int fd a 0 16
930k = sockname int fd a 0 16
931x = fclose int fd
932if or ne r 0 ne k 16
933ret 67
934end
935for i ulong 20
936c = hdial a 1000000000
937if ne c -111
938ret 68
939end
940end
941ret 0
942end
943fn main to int
944cs = new ulong 320 0
945io = new uchar 131072 0
946bg = new uchar 1048592 0
947fb = new uchar 4096 0
948f0 = fdcount fb
949if lt f0 0
950ret 95
951end
952e = tmain cs io bg
953if ne e 0
954ret e
955end
956e = tslow cs io
957if ne e 0
958ret e
959end
960e = tidle cs io
961if ne e 0
962ret e
963end
964e = tbody cs io bg
965if ne e 0
966ret e
967end
968e = tover cs io
969if ne e 0
970ret e
971end
972e = trefuse
973if ne e 0
974ret e
975end
976f1 = fdcount fb
977if ne f0 f1
978ret 96
979end
980ret 0
981end