From 47660bfee269dbe31105acf05e5a1797169ed9f1 Mon Sep 17 00:00:00 2001 From: vcptr <51714622+vcptr@users.noreply.github.com> Date: Wed, 27 Nov 2019 11:24:40 +0800 Subject: [PATCH] fix win test error; dont use ReadV on file --- common/buf/io.go | 12 +++------ common/buf/readv_constraint_other.go | 9 ------- common/buf/readv_constraint_windows.go | 37 -------------------------- 3 files changed, 4 insertions(+), 54 deletions(-) delete mode 100644 common/buf/readv_constraint_other.go delete mode 100644 common/buf/readv_constraint_windows.go diff --git a/common/buf/io.go b/common/buf/io.go index cf27ba89..2a4cd670 100644 --- a/common/buf/io.go +++ b/common/buf/io.go @@ -3,6 +3,7 @@ package buf import ( "io" "net" + "os" "syscall" "time" ) @@ -57,19 +58,14 @@ func NewReader(reader io.Reader) Reader { } } - if useReadv { + _, isFile := reader.(*os.File) + if !isFile && useReadv { if sc, ok := reader.(syscall.Conn); ok { rawConn, err := sc.SyscallConn() if err != nil { newError("failed to get sysconn").Base(err).WriteToLog() } else { - /* - Check if ReadVReader Can be used on this reader first - Fix https://github.com/v2ray/v2ray-core/issues/1666 - */ - if ok, _ := checkReadVConstraint(rawConn); ok { - return NewReadVReader(reader, rawConn) - } + return NewReadVReader(reader, rawConn) } } } diff --git a/common/buf/readv_constraint_other.go b/common/buf/readv_constraint_other.go deleted file mode 100644 index 315ce61f..00000000 --- a/common/buf/readv_constraint_other.go +++ /dev/null @@ -1,9 +0,0 @@ -// +build !windows - -package buf - -import "syscall" - -func checkReadVConstraint(conn syscall.RawConn) (bool, error) { - return true, nil -} diff --git a/common/buf/readv_constraint_windows.go b/common/buf/readv_constraint_windows.go deleted file mode 100644 index d78cbaa8..00000000 --- a/common/buf/readv_constraint_windows.go +++ /dev/null @@ -1,37 +0,0 @@ -// +build windows -package buf - -import ( - "syscall" -) - -func checkReadVConstraint(conn syscall.RawConn) (bool, error) { - var isSocketReady = false - var reason error - /* - In Windows, WSARecv system call only support socket connection. - - It it required to check if the given fd is of a socket type - - Fix https://github.com/v2ray/v2ray-core/issues/1666 - - Additional Information: - https://docs.microsoft.com/en-us/windows/desktop/api/winsock2/nf-winsock2-wsarecv - https://docs.microsoft.com/en-us/windows/desktop/api/winsock/nf-winsock-getsockopt - https://docs.microsoft.com/en-us/windows/desktop/WinSock/sol-socket-socket-options - - */ - err := conn.Control(func(fd uintptr) { - var val [4]byte - var le = int32(len(val)) - err := syscall.Getsockopt(syscall.Handle(fd), syscall.SOL_SOCKET, syscall.SO_RCVBUF, &val[0], &le) - if err != nil { - isSocketReady = false - } else { - isSocketReady = true - } - reason = err - }) - - return isSocketReady, err -}