MCPcopy Create free account
hub / github.com/encodeous/nylon / changeState

Method changeState

polyamide/device/device.go:143–171  ·  view source on GitHub ↗

changeState attempts to change the device state to match want.

(want deviceState)

Source from the content-addressed store, hash-verified

141
142// changeState attempts to change the device state to match want.
143func (device *Device) changeState(want deviceState) (err error) {
144 device.state.Lock()
145 defer device.state.Unlock()
146 old := device.deviceState()
147 if old == deviceStateClosed {
148 // once closed, always closed
149 device.Log.Verbosef("Interface closed, ignored requested state %s", want)
150 return nil
151 }
152 switch want {
153 case old:
154 return nil
155 case deviceStateUp:
156 device.state.state.Store(uint32(deviceStateUp))
157 err = device.upLocked()
158 if err == nil {
159 break
160 }
161 fallthrough // up failed; bring the device all the way back down
162 case deviceStateDown:
163 device.state.state.Store(uint32(deviceStateDown))
164 errDown := device.downLocked()
165 if err == nil {
166 err = errDown
167 }
168 }
169 device.Log.Verbosef("Interface state was %s, requested %s, now %s", old, want, device.deviceState())
170 return
171}
172
173// upLocked attempts to bring the device up and reports whether it succeeded.
174// The caller must hold device.state.mu and is responsible for updating device.state.state.

Callers 2

UpMethod · 0.95
DownMethod · 0.95

Implementers 4

NativeTunpolyamide/tun/tun_linux.go
netTunpolyamide/tun/netstack/tun.go
chTunpolyamide/tun/tuntest/tuntest.go
fakeTUNDeviceSizedpolyamide/device/device_test.go

Calls 3

deviceStateMethod · 0.95
upLockedMethod · 0.95
downLockedMethod · 0.95

Tested by

no test coverage detected