fix sendmmsg/recvmmsg compatibility issue for old linux kernel

This commit is contained in:
xtaci
2019-06-11 13:56:56 +08:00
parent 09348110eb
commit 3a4bcb9bae
2 changed files with 37 additions and 0 deletions
+23
View File
@@ -4,6 +4,7 @@ package kcp
import (
"net"
"os"
"sync/atomic"
"github.com/pkg/errors"
@@ -47,6 +48,17 @@ func (s *UDPSession) readLoop() {
s.packetInput(msg.Buffers[0][:msg.N])
}
} else {
// compatibility issue:
// for linux kernel<=2.6.32, support for sendmmsg is not available
// an error of type os.SyscallError will be returned
if operr, ok := err.(*net.OpError); ok {
if se, ok := operr.Err.(*os.SyscallError); ok {
if se.Syscall == "recvmmsg" {
s.defaultReadLoop()
return
}
}
}
s.notifyReadError(errors.WithStack(err))
return
}
@@ -90,6 +102,17 @@ func (l *Listener) monitor() {
}
}
} else {
// compatibility issue:
// for linux kernel<=2.6.32, support for sendmmsg is not available
// an error of type os.SyscallError will be returned
if operr, ok := err.(*net.OpError); ok {
if se, ok := operr.Err.(*os.SyscallError); ok {
if se.Syscall == "recvmmsg" {
l.defaultMonitor()
return
}
}
}
l.notifyReadError(errors.WithStack(err))
return
}
+14
View File
@@ -3,6 +3,8 @@
package kcp
import (
"net"
"os"
"sync/atomic"
"github.com/pkg/errors"
@@ -28,6 +30,18 @@ func (s *UDPSession) tx(txqueue []ipv4.Message) {
npkts += n
txqueue = txqueue[n:]
} else {
// compatibility issue:
// for linux kernel<=2.6.32, support for sendmmsg is not available
// an error of type os.SyscallError will be returned
if operr, ok := err.(*net.OpError); ok {
if se, ok := operr.Err.(*os.SyscallError); ok {
if se.Syscall == "sendmmsg" {
s.xconn = nil // set s.xconn to nil permanently
s.defaultTx(txqueue)
return
}
}
}
s.notifyWriteError(errors.WithStack(err))
break
}