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.
14
// Network file descritor.
16
proto, name, dir string
21
var canCancelIO = true // used for testing current package
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)
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}
36
func (fd *netFD) ok() bool { return fd != nil && fd.ctl != nil }
38
func (fd *netFD) Read(b []byte) (n int, err error) {
39
if !fd.ok() || fd.data == nil {
40
return 0, syscall.EINVAL
42
n, err = fd.data.Read(b)
43
if fd.proto == "udp" && err == io.EOF {
50
func (fd *netFD) Write(b []byte) (n int, err error) {
51
if !fd.ok() || fd.data == nil {
52
return 0, syscall.EINVAL
54
return fd.data.Write(b)
57
func (fd *netFD) CloseRead() error {
64
func (fd *netFD) CloseWrite() error {
71
func (fd *netFD) Close() error {
77
if err1 := fd.data.Close(); err1 != nil && err == nil {
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
91
return fd.file(fd.data, fd.dir+"/data")
94
func (l *TCPListener) dup() (*os.File, error) {
96
return nil, syscall.EINVAL
98
return l.fd.file(l.fd.ctl, l.fd.dir+"/ctl")
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()
106
return nil, &OpError{"dup", s, fd.laddr, err}
108
return os.NewFile(uintptr(dfd), s), nil
111
func setDeadline(fd *netFD, t time.Time) error {
112
return syscall.EPLAN9
115
func setReadDeadline(fd *netFD, t time.Time) error {
116
return syscall.EPLAN9
119
func setWriteDeadline(fd *netFD, t time.Time) error {
120
return syscall.EPLAN9
123
func setReadBuffer(fd *netFD, bytes int) error {
124
return syscall.EPLAN9
127
func setWriteBuffer(fd *netFD, bytes int) error {
128
return syscall.EPLAN9