Skip to content

Commit bdcaf73

Browse files
committed
Add documentation
1 parent 75cdc98 commit bdcaf73

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

libraries/common/io/network.effekt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,39 @@ import bytearray
55
import io/error
66

77

8-
/// A tcp handle. Should not be inspected.
8+
/// A TCP handle. Should not be inspected.
99
type Connection = Int
1010

11-
def connect(host: String, port: Int): Connection / Exception[IOError] =
12-
internal::checkResult(internal::connect(host, port))
13-
11+
/// Reads data from a TCP connection into a buffer at the given offset.
1412
def read(handle: Connection, buffer: ByteArray, offset: Int, size: Int): Int / Exception[IOError] =
1513
internal::checkResult(internal::read(handle, buffer, offset, size))
1614

15+
/// Writes data from a buffer at the given offset to a TCP connection.
1716
def write(handle: Connection, buffer: ByteArray, offset: Int, size: Int): Int / Exception[IOError] =
1817
internal::checkResult(internal::write(handle, buffer, offset, size))
1918

19+
/// Establishes a TCP connection to the specified host and port.
20+
def connect(host: String, port: Int): Connection / Exception[IOError] =
21+
internal::checkResult(internal::connect(host, port))
22+
23+
/// Closes a TCP connection and releases associated resources.
2024
def close(handle: Connection): Unit =
2125
internal::close(handle)
2226

23-
/// A tcp listener. Should not be inspected.
27+
/// A TCP listener. Should not be inspected.
2428
type Listener = Int
2529

30+
/// Creates a TCP listener bound to the specified host and port.
2631
def bind(host: String, port: Int): Listener / Exception[IOError] =
2732
internal::checkResult(internal::bind(host, port))
2833

34+
/// Starts listening for incoming connections and handles them with the provided handler function.
35+
/// Runs until `shutdown` is called on this `Listener`.
2936
def listen(listener: Listener, handler: Connection => Unit at {io, async, global}): Unit / Exception[IOError] = {
3037
internal::checkResult(internal::listen(listener, handler)); ()
3138
}
3239

40+
/// Stops a TCP listener and releases associated resources.
3341
def shutdown(listener: Listener): Unit =
3442
internal::shutdown(listener)
3543

0 commit comments

Comments
 (0)