Scoop API

scoop:scoop.http.asyncio:0.1.0

src/http2_driver.scoop

Selected production source · src/http2_driver.scoop

1package scoop.http.asyncio
3internal fun driveH2(state: H2State) {
4 val start =
5 state.lock.withLock {
6 if (state.driving)
7 false
8 else {
9 state.driving = true;
10 true
11 }
12 }
13 if (!start)
14 return
15 while (true) {
16 val actions = ArrayList<() -> Unit>()
17 val again =
18 state.lock.withLock {
19 var changed = false
20 if (!state.closed) {
21 if (state.closing)
22 changed = advanceH2Close(state, actions)
23 else {
24 try {
25 state.ownerJob?.ensureActive()
26 changed = receiveH2Events(state, actions)
27 if (!state.closing)
28 changed = checkH2Idle(state, actions) || changed
29 if (!state.closing)
30 changed = finishH2Operations(state, actions) || changed
31 if (!state.closing)
32 changed = reconcileH2Idle(state, actions) || changed
33 if (!state.closing)
34 changed = planH2Transfers(state, actions) || changed
35 if (!state.closing)
36 changed = receiveH2Events(state, actions) || changed
37 } catch (error: Throwable) {
38 terminateH2(state, error);
39 changed = true
40 }
41 }
42 }
43 if (!changed && actions.size == 0L)
44 state.driving = false
45 changed || actions.size != 0L
46 }
47 if (!again)
48 return
49 for (action in actions)
50 action()
51 }