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