~juju-qa/ubuntu/yakkety/juju/2.0-rc3-again

« back to all changes in this revision

Viewing changes to src/code.google.com/p/go.net/ipv4/helper_windows.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-04-24 22:34:47 UTC
  • Revision ID: package-import@ubuntu.com-20130424223447-f0qdji7ubnyo0s71
Tags: upstream-1.10.0.1
ImportĀ upstreamĀ versionĀ 1.10.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2012 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
package ipv4
 
6
 
 
7
import (
 
8
        "net"
 
9
        "reflect"
 
10
        "syscall"
 
11
)
 
12
 
 
13
func (c *genericOpt) sysfd() (syscall.Handle, error) {
 
14
        switch p := c.c.(type) {
 
15
        case *net.TCPConn, *net.UDPConn, *net.IPConn:
 
16
                return sysfd(p)
 
17
        }
 
18
        return syscall.InvalidHandle, errInvalidConnType
 
19
}
 
20
 
 
21
func (c *dgramOpt) sysfd() (syscall.Handle, error) {
 
22
        switch p := c.c.(type) {
 
23
        case *net.UDPConn, *net.IPConn:
 
24
                return sysfd(p.(net.Conn))
 
25
        }
 
26
        return syscall.InvalidHandle, errInvalidConnType
 
27
}
 
28
 
 
29
func (c *payloadHandler) sysfd() (syscall.Handle, error) {
 
30
        return sysfd(c.c.(net.Conn))
 
31
}
 
32
 
 
33
func (c *packetHandler) sysfd() (syscall.Handle, error) {
 
34
        return sysfd(c.c)
 
35
}
 
36
 
 
37
func sysfd(c net.Conn) (syscall.Handle, error) {
 
38
        cv := reflect.ValueOf(c)
 
39
        switch ce := cv.Elem(); ce.Kind() {
 
40
        case reflect.Struct:
 
41
                netfd := ce.FieldByName("conn").FieldByName("fd")
 
42
                switch fe := netfd.Elem(); fe.Kind() {
 
43
                case reflect.Struct:
 
44
                        fd := fe.FieldByName("sysfd")
 
45
                        return syscall.Handle(fd.Uint()), nil
 
46
                }
 
47
        }
 
48
        return syscall.InvalidHandle, errInvalidConnType
 
49
}