From a7fea3786d15e52a8c9be10472b8894ab48e3df4 Mon Sep 17 00:00:00 2001 From: Qing Liu Date: Tue, 5 Nov 2024 03:34:05 +0000 Subject: [PATCH] make windows happy --- splice/pair.go | 18 ------------------ splice/pair_darwin.go | 12 ++++++++++++ splice/pair_linux.go | 17 +++++++++++++++++ splice/pair_windows.go | 33 +++++++++++++++++++++++++++++++++ splice/splice.go | 8 -------- splice/splice_darwin.go | 13 ++++++++++++- splice/splice_linux.go | 8 ++++++++ splice/splice_windows.go | 14 ++++++++++++++ 8 files changed, 96 insertions(+), 27 deletions(-) create mode 100644 splice/pair_windows.go create mode 100644 splice/splice_windows.go diff --git a/splice/pair.go b/splice/pair.go index d7d7a42a0..1fe822e8c 100644 --- a/splice/pair.go +++ b/splice/pair.go @@ -6,7 +6,6 @@ package splice import ( "fmt" - "syscall" ) type Pair struct { @@ -42,23 +41,6 @@ func (p *Pair) Cap() int { return p.size } -func (p *Pair) Close() error { - err1 := syscall.Close(p.r) - err2 := syscall.Close(p.w) - if err1 != nil { - return err1 - } - return err2 -} - -func (p *Pair) Read(d []byte) (n int, err error) { - return syscall.Read(p.r, d) -} - -func (p *Pair) Write(d []byte) (n int, err error) { - return syscall.Write(p.w, d) -} - func (p *Pair) ReadFd() uintptr { return uintptr(p.r) } diff --git a/splice/pair_darwin.go b/splice/pair_darwin.go index f09f6c091..81c1f091b 100644 --- a/splice/pair_darwin.go +++ b/splice/pair_darwin.go @@ -19,3 +19,15 @@ func (p *Pair) WriteTo(fd uintptr, n int) (int, error) { func (p *Pair) discard() { panic("not implemented") } + +func (p *Pair) Close() error { + panic("not implemented") +} + +func (p *Pair) Read(d []byte) (n int, err error) { + panic("not implemented") +} + +func (p *Pair) Write(d []byte) (n int, err error) { + panic("not implemented") +} diff --git a/splice/pair_linux.go b/splice/pair_linux.go index c14578474..26df205ab 100644 --- a/splice/pair_linux.go +++ b/splice/pair_linux.go @@ -53,3 +53,20 @@ func (p *Pair) discard() { log.Panicf("splicing into /dev/null: %v (close R %d '%v', close W %d '%v')", err, p.r, errR, p.w, errW) } } + +func (p *Pair) Close() error { + err1 := syscall.Close(p.r) + err2 := syscall.Close(p.w) + if err1 != nil { + return err1 + } + return err2 +} + +func (p *Pair) Read(d []byte) (n int, err error) { + return syscall.Read(p.r, d) +} + +func (p *Pair) Write(d []byte) (n int, err error) { + return syscall.Write(p.w, d) +} diff --git a/splice/pair_windows.go b/splice/pair_windows.go new file mode 100644 index 000000000..81c1f091b --- /dev/null +++ b/splice/pair_windows.go @@ -0,0 +1,33 @@ +// Copyright 2016 the Go-FUSE 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 splice + +func (p *Pair) LoadFromAt(fd uintptr, sz int, off int64) (int, error) { + panic("not implemented") +} + +func (p *Pair) LoadFrom(fd uintptr, sz int) (int, error) { + panic("not implemented") +} + +func (p *Pair) WriteTo(fd uintptr, n int) (int, error) { + panic("not implemented") +} + +func (p *Pair) discard() { + panic("not implemented") +} + +func (p *Pair) Close() error { + panic("not implemented") +} + +func (p *Pair) Read(d []byte) (n int, err error) { + panic("not implemented") +} + +func (p *Pair) Write(d []byte) (n int, err error) { + panic("not implemented") +} diff --git a/splice/splice.go b/splice/splice.go index 826ba552f..043da004b 100644 --- a/splice/splice.go +++ b/splice/splice.go @@ -60,14 +60,6 @@ func init() { devNullFD = uintptr(fd) } -// copy & paste from syscall. -func fcntl(fd uintptr, cmd int, arg int) (val int, errno syscall.Errno) { - r0, _, e1 := syscall.Syscall(syscall.SYS_FCNTL, fd, uintptr(cmd), uintptr(arg)) - val = int(r0) - errno = syscall.Errno(e1) - return -} - const F_SETPIPE_SZ = 1031 const F_GETPIPE_SZ = 1032 diff --git a/splice/splice_darwin.go b/splice/splice_darwin.go index 2a2c75369..a2c29f4cf 100644 --- a/splice/splice_darwin.go +++ b/splice/splice_darwin.go @@ -1,6 +1,17 @@ package splice -import "fmt" +import ( + "fmt" + "syscall" +) + +// copy & paste from syscall. +func fcntl(fd uintptr, cmd int, arg int) (val int, errno syscall.Errno) { + r0, _, e1 := syscall.Syscall(syscall.SYS_FCNTL, fd, uintptr(cmd), uintptr(arg)) + val = int(r0) + errno = syscall.Errno(e1) + return +} func osPipe() (int, int, error) { return 0, 0, fmt.Errorf("not implemented") diff --git a/splice/splice_linux.go b/splice/splice_linux.go index 45ce92e66..64a94f6fd 100644 --- a/splice/splice_linux.go +++ b/splice/splice_linux.go @@ -2,6 +2,14 @@ package splice import "syscall" +// copy & paste from syscall. +func fcntl(fd uintptr, cmd int, arg int) (val int, errno syscall.Errno) { + r0, _, e1 := syscall.Syscall(syscall.SYS_FCNTL, fd, uintptr(cmd), uintptr(arg)) + val = int(r0) + errno = syscall.Errno(e1) + return +} + func osPipe() (int, int, error) { var fds [2]int err := syscall.Pipe2(fds[:], syscall.O_NONBLOCK) diff --git a/splice/splice_windows.go b/splice/splice_windows.go new file mode 100644 index 000000000..4f0b57696 --- /dev/null +++ b/splice/splice_windows.go @@ -0,0 +1,14 @@ +package splice + +import ( + "fmt" + "syscall" +) + +func osPipe() (int, int, error) { + return 0, 0, fmt.Errorf("not implemented") +} + +func fcntl(fd uintptr, cmd int, arg int) (val int, errno syscall.Errno) { + return 0, syscall.Errno(1) +}