/* * Copyright 2025 Ry Wiese * * Use of this source code is governed by the Apache 2.0 license * that can be found in the LICENSE.md file. */////// Type of TCP sockets, and its functions.///pubmod Net.TcpSocket {import java.io.InputStreamimport java.io.OutputStreamimport java.net.Socketuse Net.TcpSocketuse Net.TcpSocket.TcpSocket////// Type of TCP sockets.///pubenumTcpSocket(Socket, InputStream, OutputStream)instanceReadable[TcpSocket] {typeElm = Int8typeAef = IOpubdefread(buffer: Array[Int8, r], socket: TcpSocket): Result[IoError, Int32] \ r + IO =TcpSocket.read(buffer, socket) }instanceWritable[TcpSocket] {typeElm = Int8typeAef = IOpubdefwrite(buffer: Array[Int8, r], socket: TcpSocket): Result[IoError, Int32] \ r + IO =TcpSocket.write(buffer, socket) }/// Reads bytes from `socket` into `buffer` and returns the number of bytes read.pubdefread(buffer: Array[Int8, r], socket: TcpSocket): Result[IoError, Int32] \ r + IO =let TcpSocket(_, inputStream, _) = socket;Readable.read(buffer, inputStream)/// Writes the bytes in `buffer` to `socket` and returns the number of bytes written.pubdefwrite(buffer: Array[Int8, r], socket: TcpSocket): Result[IoError, Int32] \ r + IO =let TcpSocket(_, _, outputStream) = socket;Writable.write(buffer, outputStream)}