mirror of
https://github.com/daeuniverse/dae.git
synced 2025-01-05 13:08:57 +07:00
chore: refine code
This commit is contained in:
parent
899d0bd869
commit
871f6eff71
@ -26,6 +26,12 @@ type Anyfrom struct {
|
|||||||
gotGSOError bool
|
gotGSOError bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *Anyfrom) afterWrite(err error) {
|
||||||
|
if !a.gotGSOError && isGSOError(err) {
|
||||||
|
a.gotGSOError = true
|
||||||
|
}
|
||||||
|
a.RefreshTtl()
|
||||||
|
}
|
||||||
func (a *Anyfrom) RefreshTtl() {
|
func (a *Anyfrom) RefreshTtl() {
|
||||||
a.deadlineTimer.Reset(a.ttl)
|
a.deadlineTimer.Reset(a.ttl)
|
||||||
}
|
}
|
||||||
@ -60,36 +66,21 @@ func (a *Anyfrom) SyscallConn() (syscall.RawConn, error) {
|
|||||||
return a.UDPConn.SyscallConn()
|
return a.UDPConn.SyscallConn()
|
||||||
}
|
}
|
||||||
func (a *Anyfrom) WriteMsgUDP(b []byte, oob []byte, addr *net.UDPAddr) (n int, oobn int, err error) {
|
func (a *Anyfrom) WriteMsgUDP(b []byte, oob []byte, addr *net.UDPAddr) (n int, oobn int, err error) {
|
||||||
defer func() {
|
defer a.afterWrite(err)
|
||||||
if isGSOError(err) {
|
|
||||||
a.gotGSOError = true
|
|
||||||
}
|
|
||||||
a.RefreshTtl()
|
|
||||||
}()
|
|
||||||
if a.SupportGso(len(b)) {
|
if a.SupportGso(len(b)) {
|
||||||
return a.UDPConn.WriteMsgUDP(b, appendUDPSegmentSizeMsg(oob, uint16(len(b))), addr)
|
return a.UDPConn.WriteMsgUDP(b, appendUDPSegmentSizeMsg(oob, uint16(len(b))), addr)
|
||||||
}
|
}
|
||||||
return a.UDPConn.WriteMsgUDP(b, oob, addr)
|
return a.UDPConn.WriteMsgUDP(b, oob, addr)
|
||||||
}
|
}
|
||||||
func (a *Anyfrom) WriteMsgUDPAddrPort(b []byte, oob []byte, addr netip.AddrPort) (n int, oobn int, err error) {
|
func (a *Anyfrom) WriteMsgUDPAddrPort(b []byte, oob []byte, addr netip.AddrPort) (n int, oobn int, err error) {
|
||||||
defer func() {
|
defer a.afterWrite(err)
|
||||||
if isGSOError(err) {
|
|
||||||
a.gotGSOError = true
|
|
||||||
}
|
|
||||||
a.RefreshTtl()
|
|
||||||
}()
|
|
||||||
if a.SupportGso(len(b)) {
|
if a.SupportGso(len(b)) {
|
||||||
return a.UDPConn.WriteMsgUDPAddrPort(b, appendUDPSegmentSizeMsg(oob, uint16(len(b))), addr)
|
return a.UDPConn.WriteMsgUDPAddrPort(b, appendUDPSegmentSizeMsg(oob, uint16(len(b))), addr)
|
||||||
}
|
}
|
||||||
return a.UDPConn.WriteMsgUDPAddrPort(b, oob, addr)
|
return a.UDPConn.WriteMsgUDPAddrPort(b, oob, addr)
|
||||||
}
|
}
|
||||||
func (a *Anyfrom) WriteTo(b []byte, addr net.Addr) (n int, err error) {
|
func (a *Anyfrom) WriteTo(b []byte, addr net.Addr) (n int, err error) {
|
||||||
defer func() {
|
defer a.afterWrite(err)
|
||||||
if isGSOError(err) {
|
|
||||||
a.gotGSOError = true
|
|
||||||
}
|
|
||||||
a.RefreshTtl()
|
|
||||||
}()
|
|
||||||
if a.SupportGso(len(b)) {
|
if a.SupportGso(len(b)) {
|
||||||
n, _, err = a.UDPConn.WriteMsgUDP(b, appendUDPSegmentSizeMsg(nil, uint16(len(b))), addr.(*net.UDPAddr))
|
n, _, err = a.UDPConn.WriteMsgUDP(b, appendUDPSegmentSizeMsg(nil, uint16(len(b))), addr.(*net.UDPAddr))
|
||||||
return n, err
|
return n, err
|
||||||
@ -97,12 +88,7 @@ func (a *Anyfrom) WriteTo(b []byte, addr net.Addr) (n int, err error) {
|
|||||||
return a.UDPConn.WriteTo(b, addr)
|
return a.UDPConn.WriteTo(b, addr)
|
||||||
}
|
}
|
||||||
func (a *Anyfrom) WriteToUDP(b []byte, addr *net.UDPAddr) (n int, err error) {
|
func (a *Anyfrom) WriteToUDP(b []byte, addr *net.UDPAddr) (n int, err error) {
|
||||||
defer func() {
|
defer a.afterWrite(err)
|
||||||
if isGSOError(err) {
|
|
||||||
a.gotGSOError = true
|
|
||||||
}
|
|
||||||
a.RefreshTtl()
|
|
||||||
}()
|
|
||||||
if a.SupportGso(len(b)) {
|
if a.SupportGso(len(b)) {
|
||||||
n, _, err = a.UDPConn.WriteMsgUDP(b, appendUDPSegmentSizeMsg(nil, uint16(len(b))), addr)
|
n, _, err = a.UDPConn.WriteMsgUDP(b, appendUDPSegmentSizeMsg(nil, uint16(len(b))), addr)
|
||||||
return n, err
|
return n, err
|
||||||
@ -110,12 +96,7 @@ func (a *Anyfrom) WriteToUDP(b []byte, addr *net.UDPAddr) (n int, err error) {
|
|||||||
return a.UDPConn.WriteToUDP(b, addr)
|
return a.UDPConn.WriteToUDP(b, addr)
|
||||||
}
|
}
|
||||||
func (a *Anyfrom) WriteToUDPAddrPort(b []byte, addr netip.AddrPort) (n int, err error) {
|
func (a *Anyfrom) WriteToUDPAddrPort(b []byte, addr netip.AddrPort) (n int, err error) {
|
||||||
defer func() {
|
defer a.afterWrite(err)
|
||||||
if isGSOError(err) {
|
|
||||||
a.gotGSOError = true
|
|
||||||
}
|
|
||||||
a.RefreshTtl()
|
|
||||||
}()
|
|
||||||
if a.SupportGso(len(b)) {
|
if a.SupportGso(len(b)) {
|
||||||
n, _, err = a.UDPConn.WriteMsgUDPAddrPort(b, appendUDPSegmentSizeMsg(nil, uint16(len(b))), addr)
|
n, _, err = a.UDPConn.WriteMsgUDPAddrPort(b, appendUDPSegmentSizeMsg(nil, uint16(len(b))), addr)
|
||||||
return n, err
|
return n, err
|
||||||
|
Loading…
Reference in New Issue
Block a user