emmm 注册式网络栈不太好写

This commit is contained in:
impact-eintr
2022-12-18 11:17:06 +08:00
parent ba3c3429e0
commit 5b66b2f42d
4 changed files with 126 additions and 31 deletions

View File

@@ -1,12 +1,15 @@
package loopback
import (
"fmt"
"netstack/logger"
"netstack/tcpip"
"netstack/tcpip/buffer"
"netstack/tcpip/stack"
)
type endpoint struct {
count int
dispatcher stack.NetworkDispatcher
}
@@ -43,6 +46,13 @@ func (e *endpoint) WritePacket(r *stack.Route, hdr buffer.Prependable, payload b
views = append(views, payload.Views()...)
vv := buffer.NewVectorisedView(len(views[0])+payload.Size(), views)
// TODO 这里整点活 在特定的情况下丢掉数据报 模拟网络阻塞
e.count++
if e.count == 5 || e.count == 7 || e.count == 9 {
logger.NOTICE(fmt.Sprintf("统计 %d 丢掉这个报文", e.count))
return nil
}
// Because we're immediately turning around and writing the packet back to the
// rx path, we intentionally don't preserve the remote and local link
// addresses from the stack.Route we're passed.