rawconn.go 993 B

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