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
omega-mv / si / mcp / data / examples / sockets.om
| 1 | note a Unix socket pair in the working directory: socket, option, bind, listen, connect, accept, |
| 2 | note send, wait, receive, peer identity, sendmsg, poll and shutdown |
| 3 | global buf uchar 64 |
| 4 | global four uchar 4 |
| 5 | global pfd uchar 8 |
| 6 | text msg "ping" |
| 7 | fn ck yes bool to void |
| 8 | if not yes |
| 9 | exit 80 |
| 10 | end |
| 11 | end |
| 12 | fn main to int |
| 13 | na = new uchar 3 0 |
| 14 | put na 0 1 |
| 15 | put na 2 115 |
| 16 | s = int socknew 1 1 0 |
| 17 | ck ge s 0 |
| 18 | put four 0 1 |
| 19 | ck eq sockopt s 1 2 four 0 4 0 |
| 20 | ck eq bind s na 0 3 0 |
| 21 | ck eq listen s 4 0 |
| 22 | ck gt sockname s buf 0 64 0 |
| 23 | c = int socknew 1 1 0 |
| 24 | ck eq connect c na 0 3 0 |
| 25 | a = int accept s 0 |
| 26 | ck ge a 0 |
| 27 | ck eq send c msg 0 4 0 4 |
| 28 | ck gt waitio a 1 1000000000 0 |
| 29 | ck eq recv a buf 0 4 0 4 |
| 30 | ck eq peercred a buf 0 12 0 |
| 31 | ck eq sendmsg a msg 0 4 0 4 |
| 32 | put pfd 0 uchar c |
| 33 | put pfd 4 1 |
| 34 | ck eq pollfds pfd 0 8 1000000000 1 |
| 35 | ck eq shutdown c 2 0 |
| 36 | ret 0 |
| 37 | end |