Resume with EOF instead of throwing error when no data is received (#94)

This commit is contained in:
Mattt 2025-05-02 14:24:37 -07:00 • committed by GitHub
commit 2b67a1233f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -168,6 +168,11 @@ import struct Foundation.Data
while isConnected && !Task.isCancelled {
do {
let newData = try await receiveData()
// Check for EOF (empty data)
if newData.isEmpty {
logger.info("Connection closed by peer (EOF).")
break // Exit loop gracefully
}
buffer.append(newData)
// Process complete messages
@ -219,8 +224,8 @@ import struct Foundation.Data
} else if let content = content {
continuation.resume(returning: content)
} else {
continuation.resume(
throwing: MCPError.internalError("No data received"))
// EOF: Resume with empty data instead of throwing an error
continuation.resume(returning: Data())
}
}
}