| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
package udp |
| 16 |
|
| 17 |
import ( |
| 18 |
"fmt" |
| 19 |
"time" |
| 20 |
|
| 21 |
"inet.af/netstack/tcpip" |
| 22 |
"inet.af/netstack/tcpip/buffer" |
| 23 |
"inet.af/netstack/tcpip/stack" |
| 24 |
"inet.af/netstack/tcpip/transport" |
| 25 |
) |
| 26 |
|
| 27 |
|
| 28 |
func (p *udpPacket) saveReceivedAt() int64 { |
| 29 |
return p.receivedAt.UnixNano() |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
func (p *udpPacket) loadReceivedAt(nsec int64) { |
| 34 |
p.receivedAt = time.Unix(0, nsec) |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
func (p *udpPacket) saveData() buffer.VectorisedView { |
| 39 |
return p.data.Clone(nil) |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
func (p *udpPacket) loadData(data buffer.VectorisedView) { |
| 44 |
p.data = data |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
func (e *endpoint) afterLoad() { |
| 49 |
stack.StackFromEnv.RegisterRestoredEndpoint(e) |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
func (e *endpoint) beforeSave() { |
| 54 |
e.freeze() |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
func (e *endpoint) Resume(s *stack.Stack) { |
| 59 |
e.thaw() |
| 60 |
|
| 61 |
e.mu.Lock() |
| 62 |
defer e.mu.Unlock() |
| 63 |
|
| 64 |
e.net.Resume(s) |
| 65 |
|
| 66 |
e.stack = s |
| 67 |
e.ops.InitHandler(e, e.stack, tcpip.GetStackSendBufferLimits, tcpip.GetStackReceiveBufferLimits) |
| 68 |
|
| 69 |
switch state := e.net.State(); state { |
| 70 |
case transport.DatagramEndpointStateInitial, transport.DatagramEndpointStateClosed: |
| 71 |
case transport.DatagramEndpointStateBound, transport.DatagramEndpointStateConnected: |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
var err tcpip.Error |
| 76 |
id := e.net.Info().ID |
| 77 |
id.LocalPort = e.localPort |
| 78 |
id.RemotePort = e.remotePort |
| 79 |
id, e.boundBindToDevice, err = e.registerWithStack(e.effectiveNetProtos, id) |
| 80 |
if err != nil { |
| 81 |
panic(err) |
| 82 |
} |
| 83 |
e.localPort = id.LocalPort |
| 84 |
e.remotePort = id.RemotePort |
| 85 |
default: |
| 86 |
panic(fmt.Sprintf("unhandled state = %s", state)) |
| 87 |
} |
| 88 |
} |