github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/pkg/ipmi/handler.go (about)

     1  // Copyright 2019-2022 the u-root Authors. All rights reserved
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package ipmi
     6  
     7  import (
     8  	"os"
     9  	"syscall"
    10  	"time"
    11  
    12  	"golang.org/x/sys/unix"
    13  )
    14  
    15  type syscalls interface {
    16  	syscall(uintptr, uintptr, uintptr, uintptr) (uintptr, uintptr, unix.Errno)
    17  	fileSyscallConn(f *os.File) (syscall.RawConn, error)
    18  	fileSetReadDeadline(f *os.File, t time.Duration) error
    19  	connRead(f func(fd uintptr) bool, conn syscall.RawConn) error
    20  }
    21  
    22  type realSyscalls struct{}
    23  
    24  func (r *realSyscalls) syscall(trap, a1, a2, a3 uintptr) (uintptr, uintptr, unix.Errno) {
    25  	return unix.Syscall(trap, a1, a2, a3)
    26  }
    27  
    28  func (r *realSyscalls) fileSyscallConn(f *os.File) (syscall.RawConn, error) {
    29  	return f.SyscallConn()
    30  }
    31  
    32  func (r *realSyscalls) fileSetReadDeadline(f *os.File, t time.Duration) error {
    33  	return f.SetReadDeadline(time.Now().Add(t))
    34  }
    35  
    36  func (r *realSyscalls) connRead(f func(fd uintptr) bool, conn syscall.RawConn) error {
    37  	return conn.Read(f)
    38  }