Skip to content

Commit 03affbc

Browse files
committed
Fix API inconsistencies in README
- Change socket.close() from throwing to async (await socket.close()) - Fix event stream property name from 'events' to 'event' - Update socket option getter to use subscript syntax (socket[.keepAlive]) - Remove unsupported scopeID parameter from IPv6SocketAddress example
1 parent c088cca commit 03affbc

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ let response = try await socket.read(1024)
7979
print("Received: \(String(data: response, encoding: .utf8) ?? "")")
8080

8181
// Close the socket
82-
try socket.close()
82+
await socket.close()
8383
```
8484

8585
### TCP Server
@@ -109,7 +109,7 @@ while true {
109109
let response = "Hello, Client!".data(using: .utf8)!
110110
try await client.write(response)
111111

112-
try client.close()
112+
await client.close()
113113
} catch {
114114
print("Client error: \(error)")
115115
}
@@ -165,7 +165,7 @@ let socket = try await Socket(IPv4Protocol.tcp)
165165

166166
// Monitor events
167167
Task {
168-
for await event in socket.events {
168+
for await event in socket.event {
169169
switch event {
170170
case .read:
171171
let data = try await socket.read(1024)
@@ -201,7 +201,7 @@ try socket.setOption(.keepAlive, true)
201201
try socket.setOption(.noDelay, true) // Disable Nagle's algorithm
202202

203203
// Get socket option
204-
let keepAlive: Bool = try socket.getOption(.keepAlive)
204+
let keepAlive: Bool = try socket[.keepAlive]
205205
print("Keep-alive enabled: \(keepAlive)")
206206
```
207207

@@ -215,11 +215,10 @@ let socket = try await Socket(IPv6Protocol.tcp)
215215
let address = IPv6SocketAddress(address: .loopback, port: 8080)
216216
try await socket.connect(to: address)
217217

218-
// IPv6 with scope ID (for link-local addresses)
218+
// IPv6 address
219219
let linkLocal = IPv6SocketAddress(
220220
address: .init("fe80::1"),
221-
port: 8080,
222-
scopeID: 5 // Interface index
221+
port: 8080
223222
)
224223
```
225224

0 commit comments

Comments
 (0)