Debian Codegraph @

internal/wasip1/sock.go

raw
1 package wasip1
2
3 import "strconv"
4
5 const (
6 SockAcceptName = "sock_accept"
7 SockRecvName = "sock_recv"
8 SockSendName = "sock_send"
9 SockShutdownName = "sock_shutdown"
10 )
11
12 // SD Flags indicate which channels on a socket to shut down.
13 // https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#-sdflags-flagsu8
14 const (
15 // SD_RD disables further receive operations.
16 SD_RD uint8 = 1 << iota //nolint
17 // SD_WR disables further send operations.
18 SD_WR
19 )
20
21 func SdFlagsString(sdflags int) string {
22 return flagsString(sdflagNames[:], sdflags)
23 }
24
25 var sdflagNames = [...]string{
26 "RD",
27 "WR",
28 }
29
30 // SI Flags are flags provided to sock_send. As there are currently no flags defined, it must be set to zero.
31 // https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#-siflags-u16
32
33 func SiFlagsString(siflags int) string {
34 if siflags == 0 {
35 return ""
36 }
37 return strconv.Itoa(siflags)
38 }
39
40 // RI Flags are flags provided to sock_recv.
41 // https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#-riflags-flagsu16
42 const (
43 // RI_RECV_PEEK returns the message without removing it from the socket's receive queue
44 RI_RECV_PEEK uint8 = 1 << iota //nolint
45 // RI_RECV_WAITALL on byte-stream sockets, block until the full amount of data can be returned.
46 RI_RECV_WAITALL
47 )
48
49 func RiFlagsString(riflags int) string {
50 return flagsString(riflagNames[:], riflags)
51 }
52
53 var riflagNames = [...]string{
54 "RECV_PEEK",
55 "RECV_WAITALL",
56 }
57
58 // RO Flags are flags returned by sock_recv.
59 // https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#-roflags-flagsu16
60 const (
61 // RO_RECV_DATA_TRUNCATED is returned by sock_recv when message data has been truncated.
62 RO_RECV_DATA_TRUNCATED uint8 = 1 << iota //nolint
63 )
64
65 func RoFlagsString(roflags int) string {
66 return flagsString(roflagNames[:], roflags)
67 }
68
69 var roflagNames = [...]string{
70 "RECV_DATA_TRUNCATED",
71 }