Scoop API

scoop:scoop.http.asyncio:0.1.0

src/http2_reset.scoop

Selected production source · src/http2_reset.scoop

1package scoop.http.asyncio
3import scoop.asyncio.IoClosedException
5internal fun resetH2Stream(state: H2State, stream: H2Stream, error: Throwable, code: UInt,
6 actions: ArrayList<() -> Unit>, notifyFailure: Boolean = true) {
7 if (stream.disposed) return
8 stream.failure = Some(error)
9 if (state.closing) return
10 try { state.session.reset(stream.id, code) }
11 catch (failure: Throwable) { terminateH2(state, failure); return }
12 releaseH2Stream(state, stream, error, actions, notifyFailure)
15internal fun releaseH2Stream(state: H2State, stream: H2Stream, error: Throwable,
16 actions: ArrayList<() -> Unit>, notifyFailure: Boolean = true) {
17 if (stream.disposed) return
18 stopH2Idle(stream, actions)
19 stream.disposed = true
20 stream.failure = Some(error)
21 if (notifyFailure) notifyH2(state, Http2Notice.StreamFailure(stream.id, error), actions)
22 stream.data.clear(); stream.offset = 0L
23 stream.responses.clear()
24 if (present(stream.reader)) finishH2Body(state, stream, stream.reader!!, 0L, Some(error), actions)
25 if (present(stream.writer)) finishH2Body(state, stream, stream.writer!!, 0L, Some(error), actions)
26 if (present(stream.responseWaiter)) {
27 failH2Wait(stream.responseWaiter!!, error, actions)
28 stream.responseWaiter = None
29 }
30 var index = state.requests.size
31 while (index > 0L) {
32 index -= 1L
33 if (state.requests[index].stream.id == stream.id) state.requests.removeAt(index)
34 }
35 state.streams.remove(stream.id)
36 detachH2Stream(stream, actions)
39internal fun retireH2Stream(state: H2State, stream: H2Stream, actions: ArrayList<() -> Unit>) {
40 if (!stream.closed || stream.data.size != 0L || stream.responses.size != 0L ||
41 present(stream.reader) || present(stream.writer) || present(stream.responseWaiter)) return
42 if (!state.closed && h2PendingOutput(state, stream)) return
43 stopH2Idle(stream, actions)
44 state.streams.remove(stream.id)
45 detachH2Stream(stream, actions)
48internal suspend fun closeH2Stream(state: H2State, stream: H2Stream) {
49 if (state.lock.withLock { stream.disposed && stream.idleTimers == 0L }) return
50 httpJob(state.loop, false)
51 suspendCoroutine<Unit> { continuation ->
52 val actions = ArrayList<() -> Unit>()
53 val done = state.lock.withLock {
54 if (!stream.disposed) {
55 if (state.closed) releaseH2Stream(state, stream, IoClosedException(), actions, false)
56 else resetH2Stream(state, stream, IoClosedException(), 8U, actions, false)
57 }
58 if (stream.idleTimers == 0L) true else { stream.idleCloseWaiters.add(continuation); false }
59 }
60 for (action in actions) action()
61 driveH2(state)
62 if (done) continuation.resume(Unit)
63 }