You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

42 lines
969 B

  1. // Copyright 2016 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. // +build !go1.9
  5. // Package netreflect implements run-time reflection for the
  6. // facilities of net package.
  7. //
  8. // This package works only for Go 1.8 or below.
  9. package netreflect
  10. import (
  11. "errors"
  12. "net"
  13. )
  14. var (
  15. errInvalidType = errors.New("invalid type")
  16. errOpNoSupport = errors.New("operation not supported")
  17. )
  18. // SocketOf returns the socket descriptor of c.
  19. func SocketOf(c net.Conn) (uintptr, error) {
  20. switch c.(type) {
  21. case *net.TCPConn, *net.UDPConn, *net.IPConn, *net.UnixConn:
  22. return socketOf(c)
  23. default:
  24. return 0, errInvalidType
  25. }
  26. }
  27. // PacketSocketOf returns the socket descriptor of c.
  28. func PacketSocketOf(c net.PacketConn) (uintptr, error) {
  29. switch c.(type) {
  30. case *net.UDPConn, *net.IPConn, *net.UnixConn:
  31. return socketOf(c.(net.Conn))
  32. default:
  33. return 0, errInvalidType
  34. }
  35. }