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.
 
 
 

38 lines
827 B

  1. // Copyright 2017 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
  6. import (
  7. "errors"
  8. "net"
  9. )
  10. var (
  11. errInvalidType = errors.New("invalid type")
  12. errOpNoSupport = errors.New("operation not supported")
  13. )
  14. // SocketOf returns the socket descriptor of c.
  15. func SocketOf(c net.Conn) (uintptr, error) {
  16. switch c.(type) {
  17. case *net.TCPConn, *net.UDPConn, *net.IPConn, *net.UnixConn:
  18. return 0, errOpNoSupport
  19. default:
  20. return 0, errInvalidType
  21. }
  22. }
  23. // PacketSocketOf returns the socket descriptor of c.
  24. func PacketSocketOf(c net.PacketConn) (uintptr, error) {
  25. switch c.(type) {
  26. case *net.UDPConn, *net.IPConn, *net.UnixConn:
  27. return 0, errOpNoSupport
  28. default:
  29. return 0, errInvalidType
  30. }
  31. }