Refactor api
This commit is contained in:
parent
d378b6ca53
commit
b828f01643
15 changed files with 357 additions and 138 deletions
21
lwip.go
21
lwip.go
|
|
@ -54,6 +54,10 @@ func (l *LWIP) Start() error {
|
|||
}
|
||||
|
||||
func (l *LWIP) loopIn() {
|
||||
if winTun, isWintun := l.tun.(WinTun); isWintun {
|
||||
l.loopInWintun(winTun)
|
||||
return
|
||||
}
|
||||
mtu := int(l.tunMtu)
|
||||
if runtime.GOOS == "darwin" {
|
||||
mtu += 4
|
||||
|
|
@ -84,6 +88,23 @@ func (l *LWIP) loopIn() {
|
|||
}
|
||||
}
|
||||
|
||||
func (l *LWIP) loopInWintun(tun WinTun) {
|
||||
for {
|
||||
packet, release, err := tun.ReadPacket()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
_, err = l.stack.Write(packet)
|
||||
release()
|
||||
if err != nil {
|
||||
if err.Error() == "stack closed" {
|
||||
return
|
||||
}
|
||||
l.handler.NewError(context.Background(), err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (l *LWIP) Close() error {
|
||||
lwip.RegisterTCPConnHandler(nil)
|
||||
lwip.RegisterUDPConnHandler(nil)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue