Scoop API

scoop:scoop.tls.asyncio:0.1.0

src/driver.scoop

Selected production source · src/driver.scoop

1package scoop.tls.asyncio
3internal fun drive(state: TlsConnection) {
4 val start = state.lock.withLock {
5 if (state.driving) false else { state.driving = true; true }
6 }
7 if (!start) return
8 while (true) {
9 val actions = ArrayList<() -> Unit>()
10 val keepGoing = state.lock.withLock {
11 var changed = false
12 if (!state.closed) {
13 if (state.closing) changed = advanceClose(state, actions)
14 else {
15 changed = advanceProtocol(state)
16 if (!state.closing) changed = planVerification(state, actions) || changed
17 if (!state.closing) changed = planTransfers(state, actions) || changed
18 if (!state.closing) changed = finishRequests(state, actions) || changed
19 }
20 }
21 if (!changed && actions.size == 0L) state.driving = false
22 changed || actions.size != 0L
23 }
24 if (!keepGoing) return
25 for (action in actions) action()
26 }