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 {
|
while isConnected && !Task.isCancelled {
|
||||||
do {
|
do {
|
||||||
let newData = try await receiveData()
|
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)
|
buffer.append(newData)
|
||||||
|
|
||||||
// Process complete messages
|
// Process complete messages
|
||||||
|
|
@ -219,8 +224,8 @@ import struct Foundation.Data
|
||||||
} else if let content = content {
|
} else if let content = content {
|
||||||
continuation.resume(returning: content)
|
continuation.resume(returning: content)
|
||||||
} else {
|
} else {
|
||||||
continuation.resume(
|
// EOF: Resume with empty data instead of throwing an error
|
||||||
throwing: MCPError.internalError("No data received"))
|
continuation.resume(returning: Data())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue