summaryrefslogtreecommitdiffstats
path: root/vendor/golang.org/x/net/internal/netreflect/socket.go
blob: 1495b65f5922b5f2ea2e4e5031902f2e23eb6809 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build !go1.9

// Package netreflect implements run-time reflection for the
// facilities of net package.
//
// This package works only for Go 1.8 or below.
package netreflect

import (
	"errors"
	"net"
)

var (
	errInvalidType = errors.New("invalid type")
	errOpNoSupport = errors.New("operation not supported")
)

// SocketOf returns the socket descriptor of c.
func SocketOf(c net.Conn) (uintptr, error) {
	switch c.(type) {
	case *net.TCPConn, *net.UDPConn, *net.IPConn, *net.UnixConn:
		return socketOf(c)
	default:
		return 0, errInvalidType
	}
}

// PacketSocketOf returns the socket descriptor of c.
func PacketSocketOf(c net.PacketConn) (uintptr, error) {
	switch c.(type) {
	case *net.UDPConn, *net.IPConn, *net.UnixConn:
		return socketOf(c.(net.Conn))
	default:
		return 0, errInvalidType
	}
}