github.com/primecitizens/pcz/std@v0.2.1/ffi/wasm/wasi/socket.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright 2023 The Prime Citizens
     3  //
     4  // Copyright 2023 The Go Authors. All rights reserved.
     5  // Use of this source code is governed by a BSD-style
     6  // license that can be found in the LICENSE file.
     7  
     8  //go:build wasip1
     9  
    10  package wasi
    11  
    12  import (
    13  	"unsafe"
    14  )
    15  
    16  //go:wasmimport wasi_snapshot_preview1 sock_accept
    17  //go:noescape
    18  func SockAccept(fd FD, flags FDflags, newfd unsafe.Pointer) Errno
    19  
    20  type Riflags uint16
    21  
    22  const (
    23  	Riflag_RECV_PEEK    Riflags = 0x1 // Returns the message without removing it from the socket's receive queue.
    24  	Riflag_RECV_WAITALL               // On byte-stream sockets, block until the full amount of data can be returned.
    25  )
    26  
    27  type Roflags uint16
    28  
    29  const (
    30  	Roflags_RECV_DATA_TRUNCATED Roflags = 0x1 // Message data has been truncated.
    31  )
    32  
    33  type SockRecvResult struct {
    34  	NRead   Size
    35  	Roflags Roflags
    36  }
    37  
    38  // TODO: go1.21 doesn't support uint16 args
    39  
    40  // //go:wasmimport wasi_snapshot_preview1 sock_recv
    41  // //go:noescape
    42  // func SockRecv(fd FD, iovs unsafe.Pointer, n Size, riflags Riflags, result unsafe.Pointer) Errno
    43  
    44  type Siflags uint16
    45  
    46  // //go:wasmimport wasi_snapshot_preview1 sock_send
    47  // //go:noescape
    48  // func SockSend(fd FD, iovs unsafe.Pointer, n Size, siflags Siflags, nwritten Size) Errno
    49  
    50  type SDflags uint32
    51  
    52  const (
    53  	SDflag_RD SDflags = 0x1 // Disables further receive operations.
    54  	SDflag_WR SDflags = 0x2 // Disables further send operations.
    55  	SDflag_RW SDflags = SDflag_RD | SDflag_WR
    56  )
    57  
    58  //go:wasmimport wasi_snapshot_preview1 sock_shutdown
    59  //go:noescape
    60  func SockShutdown(fd FD, how SDflags) Errno