github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/sys/fuchsia/test/socket (about)

     1  # Create a socket with the ZX_SOCKET_STREAM option.
     2  
     3  zx_socket_create(0x0, &AUTO=<r0=>0x0, &AUTO=<r1=>0x0)
     4  
     5  # Create a socket with the ZX_SOCKET_DATAGRAM option.
     6  
     7  zx_socket_create(0x1, &AUTO, &AUTO)
     8  
     9  # Write some data to a ZX_SOCKET_STREAM socket.
    10  
    11  zx_socket_write(r0, 0x0, &AUTO="0a1b2c3d", 0x4, &AUTO)
    12  zx_socket_write(r0, 0x0, &AUTO="", 0x0, &AUTO)
    13  
    14  # Read some data from a ZX_SOCKET_STREAM socket, using the ZX_SOCKET_PEEK option to leave the data in the socket for a subsequent read.
    15  
    16  zx_socket_read(r1, 0x8, &AUTO, 0x10, &AUTO)
    17  zx_socket_read(r1, 0x8, &AUTO, 0x10, &AUTO)
    18  
    19  # Read all of the buffered data from a ZX_SOCKET_STREAM socket, clearing the data from the socket.
    20  
    21  zx_socket_read(r1, 0x0, &AUTO, 0x10, &AUTO)
    22  zx_socket_read(r1, 0x0, &AUTO, 0x10, &AUTO) # ZX_ERR_SHOULD_WAIT
    23  
    24  # Disable writes on a socket endpoint while enabling writes on its peer, then re-enable writes for both.
    25  
    26  zx_socket_set_disposition(r0, 0x1, 0x2)
    27  zx_socket_write(r0, 0, &AUTO="0d", 0x1, &AUTO) # ZX_ERR_BAD_STATE
    28  zx_socket_write(r1, 0, &AUTO="0e", 0x1, &AUTO)
    29  zx_socket_set_disposition(r0, 0x2, 0x2)
    30  
    31  # Write some data to a socket, then disable writes on an endpoint. It should not be possible to re-enable writes on the write-disabled peer its peer has read the buffered data.
    32  
    33  zx_socket_write(r0, 0, &AUTO="0f", 0x1, &AUTO)
    34  zx_socket_set_disposition(r0, 0x1, 0x2) 
    35  zx_socket_set_disposition(r0, 0x2, 0x2) # ZX_ERR_BAD_STATE
    36  zx_socket_read(r1, 0x0, &AUTO, 0x10, &AUTO)
    37  zx_socket_set_disposition(r0, 0x2, 0x2)