in ktor-client/ktor-client-apache/jvm/src/io/ktor/client/engine/apache/ApacheRequestProducer.kt [80:116]
override fun produceContent(encoder: ContentEncoder, ioctrl: IOControl) {
var buffer = currentBuffer.getAndSet(null) ?: requestChannel.poll()
if (buffer == null) {
@OptIn(ExperimentalCoroutinesApi::class)
if (requestChannel.isClosedForReceive) {
encoder.complete()
return
}
ioctrl.suspendOutput()
ioControl.value = ioctrl
buffer = requestChannel.poll() ?: return
ioControl.value = null
try {
ioctrl.requestOutput()
} catch (cause: Throwable) {
buffer.recycle()
throw cause
}
}
try {
encoder.write(buffer)
} catch (cause: Throwable) {
buffer.recycle()
throw cause
}
if (buffer.hasRemaining()) {
currentBuffer.value = buffer
} else {
buffer.recycle()
}
}