| | @@ -14,3 +14,47 @@ |
| 14 | 14 | (about 130 bytes) became a value parameter, copied at every call. |
| 15 | 15 | Measured once the port built: not what stands out, the compiler's |
| 16 | 16 | profile is flat (`Scan.tokPos` is 9%). |
| 17 | + |
| 18 | +## A UDP socket that serves |
| 19 | + |
| 20 | +`proc listenUdp*(addr: []U8; port: INT): INT;`, a socket of datagrams |
| 21 | +bound to `port` at `addr`, with `receive*(fd: INT; buf: []U8): (INT, |
| 22 | +Peer)` and `reply*(fd: INT; to: Peer; s: []U8): INT` to answer whoever |
| 23 | +sent each one. `connectUdp` talks to one server; nothing lets a program |
| 24 | +be one. |
| 25 | + |
| 26 | +Met in rnet, whose `Dns` test serves a name server on the loopback: |
| 27 | +`test/Nameserver.raz` binds and answers with `SYSCALL`s of its own, |
| 28 | +which tie it to Linux. |
| 29 | + |
| 30 | +## A socket's own port |
| 31 | + |
| 32 | +`proc localPort*(fd: INT): INT;` (getsockname), so that a program can |
| 33 | +listen on port 0, take the port the system chose, and tell it to its |
| 34 | +client. Without it, a test picks a port and tries again while one is |
| 35 | +taken. |
| 36 | + |
| 37 | +Met in rnet's tests, which pick ports from the process id and retry. |
| 38 | + |
| 39 | +## Connecting with a timeout |
| 40 | + |
| 41 | +`proc connectTcpWithin*(addr: []U8; port, ms: INT): INT;`: a |
| 42 | +connection that fails with -110 (ETIMEDOUT) after `ms` milliseconds, |
| 43 | +by a non-blocking connect and a wait for the socket to be writable. |
| 44 | +`connectTcp` waits as long as the kernel does, minutes for a host that |
| 45 | +drops the connection's first packet. |
| 46 | + |
| 47 | +Met in rnet: `Conn.dial`, and `Dns` over TCP to a name server that has |
| 48 | +gone, can hold a program up that long. |
| 49 | + |
| 50 | +## Thread in a program with C |
| 51 | + |
| 52 | +`Thread` says `link static`, so a program with C can't have it, and |
| 53 | +makes its threads with `C.pthread_create`, whose start procedure has |
| 54 | +another signature. A library that starts threads, and may be used by |
| 55 | +programs with C and without, can't name either: `Thread` could have a |
| 56 | +second file, over `pthread_create` and `pthread_join`, chosen when the |
| 57 | +program uses C, with the same `spawn` and `join`. |
| 58 | + |
| 59 | +Met in rnet: `Http`'s server is used with `Tls`, which is C, and |
| 60 | +without; it takes a `spawn` procedure from the program instead. |