github.com/lovishpuri/go-40569/src@v0.0.0-20230519171745-f8623e7c56cf/os/rawconn.go (about)

     1  // Copyright 2018 The Go 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  //go:build !plan9
     6  
     7  package os
     8  
     9  import (
    10  	"runtime"
    11  )
    12  
    13  // rawConn implements syscall.RawConn.
    14  type rawConn struct {
    15  	file *File
    16  }
    17  
    18  func (c *rawConn) Control(f func(uintptr)) error {
    19  	if err := c.file.checkValid("SyscallConn.Control"); err != nil {
    20  		return err
    21  	}
    22  	err := c.file.pfd.RawControl(f)
    23  	runtime.KeepAlive(c.file)
    24  	return err
    25  }
    26  
    27  func (c *rawConn) Read(f func(uintptr) bool) error {
    28  	if err := c.file.checkValid("SyscallConn.Read"); err != nil {
    29  		return err
    30  	}
    31  	err := c.file.pfd.RawRead(f)
    32  	runtime.KeepAlive(c.file)
    33  	return err
    34  }
    35  
    36  func (c *rawConn) Write(f func(uintptr) bool) error {
    37  	if err := c.file.checkValid("SyscallConn.Write"); err != nil {
    38  		return err
    39  	}
    40  	err := c.file.pfd.RawWrite(f)
    41  	runtime.KeepAlive(c.file)
    42  	return err
    43  }
    44  
    45  func newRawConn(file *File) (*rawConn, error) {
    46  	return &rawConn{file: file}, nil
    47  }