github.com/database64128/shadowsocks-go@v1.10.2-0.20240315062903-143a773533f1/conn/conn_flags_tclass.go (about) 1 //go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || zos 2 3 package conn 4 5 import ( 6 "errors" 7 8 "golang.org/x/sys/unix" 9 ) 10 11 var ( 12 ErrMessageTruncated = errors.New("the packet is larger than the supplied buffer") 13 ErrControlMessageTruncated = errors.New("the control message is larger than the supplied buffer") 14 ) 15 16 // ParseFlagsForError parses the message flags returned by 17 // the ReadMsgUDPAddrPort method and returns an error if MSG_TRUNC 18 // is set, indicating that the returned packet was truncated. 19 // 20 // The check is skipped on Windows, because an error (WSAEMSGSIZE) 21 // is also returned when MSG_PARTIAL is set. 22 func ParseFlagsForError(flags int) error { 23 if flags&unix.MSG_TRUNC != 0 { 24 return ErrMessageTruncated 25 } 26 27 if flags&unix.MSG_CTRUNC != 0 { 28 return ErrControlMessageTruncated 29 } 30 31 return nil 32 } 33 34 func (fns setFuncSlice) appendSetTrafficClassFunc(trafficClass int) setFuncSlice { 35 if trafficClass != 0 { 36 return append(fns, func(fd int, network string) error { 37 return setTrafficClass(fd, network, trafficClass) 38 }) 39 } 40 return fns 41 }