$64 GRAYBYTE WORDPRESS FILE MANAGER $65

SERVER : vnpttt-amd7f72-h1.vietnix.vn #1 SMP Fri May 24 12:42:50 UTC 2024
SERVER IP : 103.200.23.149 | ADMIN IP 216.73.216.22
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/lib/golang/src/os/

HOME
Current File : /lib/golang/src/os//zero_copy_linux.go
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package os

import (
	"internal/poll"
	"io"
	"syscall"
)

var (
	pollCopyFileRange = poll.CopyFileRange
	pollSplice        = poll.Splice
)

func (f *File) writeTo(w io.Writer) (written int64, handled bool, err error) {
	pfd, network := getPollFDAndNetwork(w)
	// TODO(panjf2000): same as File.spliceToFile.
	if pfd == nil || !pfd.IsStream || !isUnixOrTCP(string(network)) {
		return
	}

	sc, err := f.SyscallConn()
	if err != nil {
		return
	}

	rerr := sc.Read(func(fd uintptr) (done bool) {
		written, err, handled = poll.SendFile(pfd, fd, 0)
		return true
	})

	if err == nil {
		err = rerr
	}

	return written, handled, wrapSyscallError("sendfile", err)
}

func (f *File) readFrom(r io.Reader) (written int64, handled bool, err error) {
	// Neither copy_file_range(2) nor splice(2) supports destinations opened with
	// O_APPEND, so don't bother to try zero-copy with these system calls.
	//
	// Visit https://man7.org/linux/man-pages/man2/copy_file_range.2.html#ERRORS and
	// https://man7.org/linux/man-pages/man2/splice.2.html#ERRORS for details.
	if f.appendMode {
		return 0, false, nil
	}

	written, handled, err = f.copyFileRange(r)
	if handled {
		return
	}
	return f.spliceToFile(r)
}

func (f *File) spliceToFile(r io.Reader) (written int64, handled bool, err error) {
	var (
		remain int64
		lr     *io.LimitedReader
	)
	if lr, r, remain = tryLimitedReader(r); remain <= 0 {
		return 0, true, nil
	}

	pfd, _ := getPollFDAndNetwork(r)
	// TODO(panjf2000): run some tests to see if we should unlock the non-streams for splice.
	// Streams benefit the most from the splice(2), non-streams are not even supported in old kernels
	// where splice(2) will just return EINVAL; newer kernels support non-streams like UDP, but I really
	// doubt that splice(2) could help non-streams, cuz they usually send small frames respectively
	// and one splice call would result in one frame.
	// splice(2) is suitable for large data but the generation of fragments defeats its edge here.
	// Therefore, don't bother to try splice if the r is not a streaming descriptor.
	if pfd == nil || !pfd.IsStream {
		return
	}

	written, handled, err = pollSplice(&f.pfd, pfd, remain)

	if lr != nil {
		lr.N = remain - written
	}

	return written, handled, wrapSyscallError("splice", err)
}

func (f *File) copyFileRange(r io.Reader) (written int64, handled bool, err error) {
	var (
		remain int64
		lr     *io.LimitedReader
	)
	if lr, r, remain = tryLimitedReader(r); remain <= 0 {
		return 0, true, nil
	}

	var src *File
	switch v := r.(type) {
	case *File:
		src = v
	case fileWithoutWriteTo:
		src = v.File
	default:
		return 0, false, nil
	}

	if src.checkValid("ReadFrom") != nil {
		// Avoid returning the error as we report handled as false,
		// leave further error handling as the responsibility of the caller.
		return 0, false, nil
	}

	written, handled, err = pollCopyFileRange(&f.pfd, &src.pfd, remain)
	if lr != nil {
		lr.N -= written
	}
	return written, handled, wrapSyscallError("copy_file_range", err)
}

// getPollFDAndNetwork tries to get the poll.FD and network type from the given interface
// by expecting the underlying type of i to be the implementation of syscall.Conn
// that contains a *net.rawConn.
func getPollFDAndNetwork(i any) (*poll.FD, poll.String) {
	sc, ok := i.(syscall.Conn)
	if !ok {
		return nil, ""
	}
	rc, err := sc.SyscallConn()
	if err != nil {
		return nil, ""
	}
	irc, ok := rc.(interface {
		PollFD() *poll.FD
		Network() poll.String
	})
	if !ok {
		return nil, ""
	}
	return irc.PollFD(), irc.Network()
}

func isUnixOrTCP(network string) bool {
	switch network {
	case "tcp", "tcp4", "tcp6", "unix":
		return true
	default:
		return false
	}
}

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
16 Dec 2025 9.30 PM
root / root
0755
exec
--
16 Dec 2025 9.30 PM
root / root
0755
signal
--
16 Dec 2025 9.30 PM
root / root
0755
user
--
16 Dec 2025 9.30 PM
root / root
0755
dir.go
5.935 KB
4 Dec 2025 6.06 PM
root / root
0644
dir_darwin.go
3.498 KB
4 Dec 2025 6.06 PM
root / root
0644
dir_plan9.go
2.189 KB
4 Dec 2025 6.06 PM
root / root
0644
dir_unix.go
4.846 KB
4 Dec 2025 6.06 PM
root / root
0644
dir_windows.go
7.684 KB
4 Dec 2025 6.06 PM
root / root
0644
dirent_aix.go
0.741 KB
4 Dec 2025 6.06 PM
root / root
0644
dirent_dragonfly.go
1.279 KB
4 Dec 2025 6.06 PM
root / root
0644
dirent_freebsd.go
1.159 KB
4 Dec 2025 6.06 PM
root / root
0644
dirent_js.go
0.662 KB
4 Dec 2025 6.06 PM
root / root
0644
dirent_linux.go
1.184 KB
4 Dec 2025 6.06 PM
root / root
0644
dirent_netbsd.go
1.159 KB
4 Dec 2025 6.06 PM
root / root
0644
dirent_openbsd.go
1.159 KB
4 Dec 2025 6.06 PM
root / root
0644
dirent_solaris.go
0.741 KB
4 Dec 2025 6.06 PM
root / root
0644
dirent_wasip1.go
1.355 KB
4 Dec 2025 6.06 PM
root / root
0644
eloop_netbsd.go
0.496 KB
4 Dec 2025 6.06 PM
root / root
0644
eloop_other.go
0.646 KB
4 Dec 2025 6.06 PM
root / root
0644
env.go
3.854 KB
4 Dec 2025 6.06 PM
root / root
0644
error.go
4.796 KB
4 Dec 2025 6.06 PM
root / root
0644
error_errno.go
0.334 KB
4 Dec 2025 6.06 PM
root / root
0644
error_plan9.go
0.395 KB
4 Dec 2025 6.06 PM
root / root
0644
exec.go
11.473 KB
4 Dec 2025 6.06 PM
root / root
0644
exec_linux.go
0.263 KB
4 Dec 2025 6.06 PM
root / root
0644
exec_nohandle.go
0.296 KB
4 Dec 2025 6.06 PM
root / root
0644
exec_plan9.go
3.231 KB
4 Dec 2025 6.06 PM
root / root
0644
exec_posix.go
3.71 KB
4 Dec 2025 6.06 PM
root / root
0644
exec_unix.go
3.323 KB
4 Dec 2025 6.06 PM
root / root
0644
exec_windows.go
4.677 KB
4 Dec 2025 6.06 PM
root / root
0644
executable.go
0.758 KB
4 Dec 2025 6.06 PM
root / root
0644
executable_darwin.go
0.659 KB
4 Dec 2025 6.06 PM
root / root
0644
executable_dragonfly.go
0.362 KB
4 Dec 2025 6.06 PM
root / root
0644
executable_freebsd.go
0.361 KB
4 Dec 2025 6.06 PM
root / root
0644
executable_netbsd.go
0.364 KB
4 Dec 2025 6.06 PM
root / root
0644
executable_path.go
2.309 KB
4 Dec 2025 6.06 PM
root / root
0644
executable_plan9.go
0.417 KB
4 Dec 2025 6.06 PM
root / root
0644
executable_procfs.go
0.643 KB
4 Dec 2025 6.06 PM
root / root
0644
executable_solaris.go
0.739 KB
4 Dec 2025 6.06 PM
root / root
0644
executable_sysctl.go
0.835 KB
4 Dec 2025 6.06 PM
root / root
0644
executable_wasm.go
0.325 KB
4 Dec 2025 6.06 PM
root / root
0644
executable_windows.go
0.626 KB
4 Dec 2025 6.06 PM
root / root
0644
file.go
29.511 KB
4 Dec 2025 6.06 PM
root / root
0644
file_mutex_plan9.go
1.809 KB
4 Dec 2025 6.06 PM
root / root
0644
file_open_unix.go
0.388 KB
4 Dec 2025 6.06 PM
root / root
0644
file_open_wasip1.go
0.799 KB
4 Dec 2025 6.06 PM
root / root
0644
file_plan9.go
15.686 KB
4 Dec 2025 6.06 PM
root / root
0644
file_posix.go
7.47 KB
4 Dec 2025 6.06 PM
root / root
0644
file_unix.go
13.718 KB
4 Dec 2025 6.06 PM
root / root
0644
file_wasip1.go
0.618 KB
4 Dec 2025 6.06 PM
root / root
0644
file_windows.go
13.51 KB
4 Dec 2025 6.06 PM
root / root
0644
getwd.go
3.71 KB
4 Dec 2025 6.06 PM
root / root
0644
path.go
2.307 KB
4 Dec 2025 6.06 PM
root / root
0644
path_plan9.go
0.433 KB
4 Dec 2025 6.06 PM
root / root
0644
path_unix.go
1.155 KB
4 Dec 2025 6.06 PM
root / root
0644
path_windows.go
5.943 KB
4 Dec 2025 6.06 PM
root / root
0644
pidfd_linux.go
5.879 KB
4 Dec 2025 6.06 PM
root / root
0644
pidfd_other.go
0.662 KB
4 Dec 2025 6.06 PM
root / root
0644
pipe2_unix.go
0.639 KB
4 Dec 2025 6.06 PM
root / root
0644
pipe_unix.go
0.756 KB
4 Dec 2025 6.06 PM
root / root
0644
pipe_wasm.go
0.477 KB
4 Dec 2025 6.06 PM
root / root
0644
proc.go
2.272 KB
4 Dec 2025 6.06 PM
root / root
0644
rawconn.go
0.97 KB
4 Dec 2025 6.06 PM
root / root
0644
removeall_at.go
4.783 KB
4 Dec 2025 6.06 PM
root / root
0644
removeall_noat.go
3.145 KB
4 Dec 2025 6.06 PM
root / root
0644
removeall_unix.go
0.469 KB
4 Dec 2025 6.06 PM
root / root
0644
removeall_windows.go
0.383 KB
4 Dec 2025 6.06 PM
root / root
0644
root.go
13.48 KB
4 Dec 2025 6.06 PM
root / root
0644
root_js.go
2.602 KB
4 Dec 2025 6.06 PM
root / root
0644
root_nonwindows.go
0.275 KB
4 Dec 2025 6.06 PM
root / root
0644
root_noopenat.go
7.861 KB
4 Dec 2025 6.06 PM
root / root
0644
root_openat.go
11.419 KB
4 Dec 2025 6.06 PM
root / root
0644
root_plan9.go
0.485 KB
4 Dec 2025 6.06 PM
root / root
0644
root_unix.go
8.497 KB
4 Dec 2025 6.06 PM
root / root
0644
root_windows.go
12.229 KB
4 Dec 2025 6.06 PM
root / root
0644
stat.go
0.95 KB
4 Dec 2025 6.06 PM
root / root
0644
stat_aix.go
1.211 KB
4 Dec 2025 6.06 PM
root / root
0644
stat_darwin.go
1.122 KB
4 Dec 2025 6.06 PM
root / root
0644
stat_dragonfly.go
1.096 KB
4 Dec 2025 6.06 PM
root / root
0644
stat_freebsd.go
1.105 KB
4 Dec 2025 6.06 PM
root / root
0644
stat_js.go
1.147 KB
4 Dec 2025 6.06 PM
root / root
0644
stat_linux.go
1.096 KB
4 Dec 2025 6.06 PM
root / root
0644
stat_netbsd.go
1.105 KB
4 Dec 2025 6.06 PM
root / root
0644
stat_openbsd.go
1.096 KB
4 Dec 2025 6.06 PM
root / root
0644
stat_plan9.go
2.375 KB
4 Dec 2025 6.06 PM
root / root
0644
stat_solaris.go
1.337 KB
4 Dec 2025 6.06 PM
root / root
0644
stat_unix.go
1.215 KB
4 Dec 2025 6.06 PM
root / root
0644
stat_wasip1.go
1.241 KB
4 Dec 2025 6.06 PM
root / root
0644
stat_windows.go
5.356 KB
4 Dec 2025 6.06 PM
root / root
0644
sticky_bsd.go
0.415 KB
4 Dec 2025 6.06 PM
root / root
0644
sticky_notbsd.go
0.313 KB
4 Dec 2025 6.06 PM
root / root
0644
sys.go
0.287 KB
4 Dec 2025 6.06 PM
root / root
0644
sys_aix.go
0.666 KB
4 Dec 2025 6.06 PM
root / root
0644
sys_bsd.go
0.455 KB
4 Dec 2025 6.06 PM
root / root
0644
sys_js.go
0.306 KB
4 Dec 2025 6.06 PM
root / root
0644
sys_linux.go
1.045 KB
4 Dec 2025 6.06 PM
root / root
0644
sys_plan9.go
0.442 KB
4 Dec 2025 6.06 PM
root / root
0644
sys_solaris.go
0.259 KB
4 Dec 2025 6.06 PM
root / root
0644
sys_unix.go
0.481 KB
4 Dec 2025 6.06 PM
root / root
0644
sys_wasip1.go
0.302 KB
4 Dec 2025 6.06 PM
root / root
0644
sys_windows.go
0.854 KB
4 Dec 2025 6.06 PM
root / root
0644
tempfile.go
3.921 KB
4 Dec 2025 6.06 PM
root / root
0644
types.go
2.858 KB
4 Dec 2025 6.06 PM
root / root
0644
types_plan9.go
0.778 KB
4 Dec 2025 6.06 PM
root / root
0644
types_unix.go
0.758 KB
4 Dec 2025 6.06 PM
root / root
0644
types_windows.go
11.714 KB
4 Dec 2025 6.06 PM
root / root
0644
wait6_dragonfly.go
0.484 KB
4 Dec 2025 6.06 PM
root / root
0644
wait6_freebsd64.go
0.534 KB
4 Dec 2025 6.06 PM
root / root
0644
wait6_freebsd_386.go
0.531 KB
4 Dec 2025 6.06 PM
root / root
0644
wait6_freebsd_arm.go
0.536 KB
4 Dec 2025 6.06 PM
root / root
0644
wait6_netbsd.go
0.521 KB
4 Dec 2025 6.06 PM
root / root
0644
wait_unimp.go
0.812 KB
4 Dec 2025 6.06 PM
root / root
0644
wait_wait6.go
0.773 KB
4 Dec 2025 6.06 PM
root / root
0644
wait_waitid.go
1.033 KB
4 Dec 2025 6.06 PM
root / root
0644
zero_copy_freebsd.go
1.323 KB
4 Dec 2025 6.06 PM
root / root
0644
zero_copy_linux.go
3.755 KB
4 Dec 2025 6.06 PM
root / root
0644
zero_copy_posix.go
1.065 KB
4 Dec 2025 6.06 PM
root / root
0644
zero_copy_solaris.go
2.568 KB
4 Dec 2025 6.06 PM
root / root
0644
zero_copy_stub.go
0.42 KB
4 Dec 2025 6.06 PM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF