~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/net/fd_plan9.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2009 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 net
 
6
 
 
7
import (
 
8
        "io"
 
9
        "os"
 
10
        "syscall"
 
11
        "time"
 
12
)
 
13
 
 
14
// Network file descritor.
 
15
type netFD struct {
 
16
        proto, name, dir string
 
17
        ctl, data        *os.File
 
18
        laddr, raddr     Addr
 
19
}
 
20
 
 
21
var canCancelIO = true // used for testing current package
 
22
 
 
23
func sysInit() {
 
24
}
 
25
 
 
26
func resolveAndDial(net, addr string, localAddr Addr, deadline time.Time) (Conn, error) {
 
27
        // On plan9, use the relatively inefficient
 
28
        // goroutine-racing implementation.
 
29
        return resolveAndDialChannel(net, addr, localAddr, deadline)
 
30
}
 
31
 
 
32
func newFD(proto, name string, ctl, data *os.File, laddr, raddr Addr) *netFD {
 
33
        return &netFD{proto, name, "/net/" + proto + "/" + name, ctl, data, laddr, raddr}
 
34
}
 
35
 
 
36
func (fd *netFD) ok() bool { return fd != nil && fd.ctl != nil }
 
37
 
 
38
func (fd *netFD) Read(b []byte) (n int, err error) {
 
39
        if !fd.ok() || fd.data == nil {
 
40
                return 0, syscall.EINVAL
 
41
        }
 
42
        n, err = fd.data.Read(b)
 
43
        if fd.proto == "udp" && err == io.EOF {
 
44
                n = 0
 
45
                err = nil
 
46
        }
 
47
        return
 
48
}
 
49
 
 
50
func (fd *netFD) Write(b []byte) (n int, err error) {
 
51
        if !fd.ok() || fd.data == nil {
 
52
                return 0, syscall.EINVAL
 
53
        }
 
54
        return fd.data.Write(b)
 
55
}
 
56
 
 
57
func (fd *netFD) CloseRead() error {
 
58
        if !fd.ok() {
 
59
                return syscall.EINVAL
 
60
        }
 
61
        return syscall.EPLAN9
 
62
}
 
63
 
 
64
func (fd *netFD) CloseWrite() error {
 
65
        if !fd.ok() {
 
66
                return syscall.EINVAL
 
67
        }
 
68
        return syscall.EPLAN9
 
69
}
 
70
 
 
71
func (fd *netFD) Close() error {
 
72
        if !fd.ok() {
 
73
                return syscall.EINVAL
 
74
        }
 
75
        err := fd.ctl.Close()
 
76
        if fd.data != nil {
 
77
                if err1 := fd.data.Close(); err1 != nil && err == nil {
 
78
                        err = err1
 
79
                }
 
80
        }
 
81
        fd.ctl = nil
 
82
        fd.data = nil
 
83
        return err
 
84
}
 
85
 
 
86
// This method is only called via Conn.
 
87
func (fd *netFD) dup() (*os.File, error) {
 
88
        if !fd.ok() || fd.data == nil {
 
89
                return nil, syscall.EINVAL
 
90
        }
 
91
        return fd.file(fd.data, fd.dir+"/data")
 
92
}
 
93
 
 
94
func (l *TCPListener) dup() (*os.File, error) {
 
95
        if !l.fd.ok() {
 
96
                return nil, syscall.EINVAL
 
97
        }
 
98
        return l.fd.file(l.fd.ctl, l.fd.dir+"/ctl")
 
99
}
 
100
 
 
101
func (fd *netFD) file(f *os.File, s string) (*os.File, error) {
 
102
        syscall.ForkLock.RLock()
 
103
        dfd, err := syscall.Dup(int(f.Fd()), -1)
 
104
        syscall.ForkLock.RUnlock()
 
105
        if err != nil {
 
106
                return nil, &OpError{"dup", s, fd.laddr, err}
 
107
        }
 
108
        return os.NewFile(uintptr(dfd), s), nil
 
109
}
 
110
 
 
111
func setDeadline(fd *netFD, t time.Time) error {
 
112
        return syscall.EPLAN9
 
113
}
 
114
 
 
115
func setReadDeadline(fd *netFD, t time.Time) error {
 
116
        return syscall.EPLAN9
 
117
}
 
118
 
 
119
func setWriteDeadline(fd *netFD, t time.Time) error {
 
120
        return syscall.EPLAN9
 
121
}
 
122
 
 
123
func setReadBuffer(fd *netFD, bytes int) error {
 
124
        return syscall.EPLAN9
 
125
}
 
126
 
 
127
func setWriteBuffer(fd *netFD, bytes int) error {
 
128
        return syscall.EPLAN9
 
129
}