Comments and error mapping

This commit is contained in:
Hugh Nimmo-Smith 2022-10-17 12:05:32 +01:00
parent 4306c57236
commit fb86ab70a2

View File

@ -99,9 +99,8 @@ class SimpleHttpRendezvousTransport(override var onCancelled: ((reason: Rendezvo
override suspend fun receive(): ByteArray? { override suspend fun receive(): ByteArray? {
val uri = uri ?: throw IllegalStateException("Rendezvous not set up") val uri = uri ?: throw IllegalStateException("Rendezvous not set up")
var done = false
val httpClient = okhttp3.OkHttpClient.Builder().build() val httpClient = okhttp3.OkHttpClient.Builder().build()
while (!done) { while (true) {
if (cancelled) { if (cancelled) {
return null return null
} }
@ -117,8 +116,9 @@ class SimpleHttpRendezvousTransport(override var onCancelled: ((reason: Rendezvo
val response = httpClient.newCall(request.build()).execute() val response = httpClient.newCall(request.build()).execute()
try { try {
// expired
if (response.code == 404) { if (response.code == 404) {
cancel(RendezvousFailureReason.Unknown) cancel(RendezvousFailureReason.Expired)
return null return null
} }
@ -135,7 +135,8 @@ class SimpleHttpRendezvousTransport(override var onCancelled: ((reason: Rendezvo
return response.body?.bytes() return response.body?.bytes()
} }
done = false // sleep for a second before polling again
// we rely on the server expiring the channel rather than checking it ourselves
delay(1000) delay(1000)
} finally { } finally {
response.close() response.close()