Resume with EOF instead of throwing error when no data is received (#94)
This commit is contained in:
parent
48c19c282b
commit
2b67a1233f
1 changed files with 7 additions and 2 deletions
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue