Class WasiSocket

    • Constructor Detail

      • WasiSocket

        public WasiSocket()
      • WasiSocket

        public WasiSocket​(java.net.Socket socket)
                   throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • isConnected

        public boolean isConnected()
      • connect

        public int connect​(java.net.InetSocketAddress address)
      • read

        public int read​(byte[] data,
                        int offset,
                        int len)
                 throws java.io.IOException
        Description copied from interface: ReadableIO
        Reads length bytes of data from this WasiIO into an array of bytes.
        Specified by:
        read in interface ReadableIO
        Parameters:
        data - the buffer into which the data is read.
        offset - the start offset in array b at which the data is written.
        len - the maximum number of bytes to read.
        Returns:
        the total number of bytes read into the buffer or -1 if there is no more data.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • write

        public void write​(byte[] data,
                          int offset,
                          int len)
                   throws java.io.IOException
        Description copied from interface: WritableIO
        Writes length bytes from t he specified byte array starting at offset offset to this WasiIO.
        Specified by:
        write in interface WritableIO
        Parameters:
        data - the data to write.
        offset - the starting offset.
        len - the number of bytes to write.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • available

        public int available()
                      throws java.io.IOException
        Retrieve the number of bytes available for reading on the socket.
        Specified by:
        available in interface ReadableIO
        Returns:
        the number of bytes available for reading on the socket.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • getType

        public FileType getType()
        Description copied from interface: WasiIO
        Gets the WasiIO file descriptor type.
        Specified by:
        getType in interface WasiIO
        Returns:
        the WasiIO file descriptor type.
      • setNonBlocking

        public void setNonBlocking​(boolean nonBlockingMode)
        Description copied from interface: WasiSocketOpt
        Enable/disable the non blocking state on this WasiIO
        Specified by:
        setNonBlocking in interface ReadableIO
        Specified by:
        setNonBlocking in interface WasiSocketOpt
        Parameters:
        nonBlockingMode - whether to enable or disable the non-blocking socket option
      • setBroadcast

        public void setBroadcast​(boolean on)
                          throws java.io.IOException
        Description copied from interface: WasiSocketOpt
        Enable/disable the SO_BROADCAST socket option. Only meaningful for datagram sockets; stream sockets should ignore this call.
        Specified by:
        setBroadcast in interface WasiSocketOpt
        Parameters:
        on - whether to enable or disable broadcast
        Throws:
        java.io.IOException - if an I/O error occurs.
      • getBroadcast

        public boolean getBroadcast()
                             throws java.io.IOException
        Description copied from interface: WasiSocketOpt
        Get the SO_BROADCAST socket option. Only meaningful for datagram sockets; stream and server sockets always return false.
        Specified by:
        getBroadcast in interface WasiSocketOpt
        Returns:
        whether broadcast is enabled
        Throws:
        java.io.IOException - if an I/O error occurs.
      • setReuseAddress

        public void setReuseAddress​(boolean on)
                             throws java.io.IOException
        Description copied from interface: WasiSocketOpt
        Enable/disable the reuse address socket option.
        Specified by:
        setReuseAddress in interface WasiSocketOpt
        Parameters:
        on - whether to enable or disable the reuse address socket option
        Throws:
        java.io.IOException - if an I/O error occurs.
      • setReceiveBufferSize

        public void setReceiveBufferSize​(int size)
                                  throws java.io.IOException
        Description copied from interface: WasiSocketOpt
        Set the receive buffer size (SO_RCVBUF).
        Specified by:
        setReceiveBufferSize in interface WasiSocketOpt
        Parameters:
        size - the buffer size in bytes
        Throws:
        java.io.IOException - if an I/O error occurs.
      • getReceiveBufferSize

        public int getReceiveBufferSize()
                                 throws java.io.IOException
        Description copied from interface: WasiSocketOpt
        Get the receive buffer size (SO_RCVBUF).
        Specified by:
        getReceiveBufferSize in interface WasiSocketOpt
        Returns:
        the buffer size in bytes
        Throws:
        java.io.IOException - if an I/O error occurs.
      • setSendBufferSize

        public void setSendBufferSize​(int size)
                               throws java.io.IOException
        Description copied from interface: WasiSocketOpt
        Set the send buffer size (SO_SNDBUF).
        Specified by:
        setSendBufferSize in interface WasiSocketOpt
        Parameters:
        size - the buffer size in bytes
        Throws:
        java.io.IOException - if an I/O error occurs.
      • getSendBufferSize

        public int getSendBufferSize()
                              throws java.io.IOException
        Description copied from interface: WasiSocketOpt
        Get the send buffer size (SO_SNDBUF).
        Specified by:
        getSendBufferSize in interface WasiSocketOpt
        Returns:
        the buffer size in bytes
        Throws:
        java.io.IOException - if an I/O error occurs.
      • getRemoteSocketAddress

        @Nullable
        public java.net.SocketAddress getRemoteSocketAddress()
      • getLocalSocketAddress

        @Nullable
        public java.net.SocketAddress getLocalSocketAddress()
      • isNonBlocking

        public boolean isNonBlocking()
      • isReuseAddress

        public boolean isReuseAddress()
      • wasiShutdown

        public int wasiShutdown​(int how)
      • getSocket

        @Nullable
        public java.net.Socket getSocket()
      • wasiSockReceive

        public int wasiSockReceive​(int iovecListPtr,
                                   int iovecLen,
                                   int riFlags,
                                   int nbRecvPtr,
                                   int roFlagsPtr,
                                   byte[] memory)
      • wasiSockSend

        public int wasiSockSend​(int iovecListPtr,
                                int iovecLen,
                                int nbSendPtr,
                                byte[] memory)
      • isConnectionReset

        public boolean isConnectionReset()
                                  throws java.io.IOException
        Check whether the connection been reset by the peer.
        Returns:
        connection reset status.
        Throws:
        java.io.IOException - if the socket is not connected or an I/O error occurs.
      • attachWasiSSL

        public void attachWasiSSL​(@Nullable
                                  WasiSSL wasiSSL)
        Attach a WasiSSL context with the current WasiSocket. It is used in WasiSSL.SSL_set_fd(WasmModule,int,int) to attach the newly created TLS socket to the WasiSocket file descriptor. It is used in WasiSSL.close() and WasiSSL.SSL_free(WasmModule,int) to detach the TLS socket from the current WasiSocket.
        Parameters:
        wasiSSL - the WasiSSL context.
      • getWasiSSL

        @Nullable
        public WasiSSL getWasiSSL()
        Retrieve the associated WasiSSL context.
        Returns:
        the WasiSSL context.