libgo: update to Go 1.11
[official-gcc.git] / libgo / go / net / file.go
blob81a44e1f3f3d8ecaf81866428e7bd3ea0bdd6738
1 // Copyright 2015 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.
5 package net
7 import "os"
9 // BUG(mikio): On JS, NaCl and Windows, the FileConn, FileListener and
10 // FilePacketConn functions are not implemented.
12 type fileAddr string
14 func (fileAddr) Network() string { return "file+net" }
15 func (f fileAddr) String() string { return string(f) }
17 // FileConn returns a copy of the network connection corresponding to
18 // the open file f.
19 // It is the caller's responsibility to close f when finished.
20 // Closing c does not affect f, and closing f does not affect c.
21 func FileConn(f *os.File) (c Conn, err error) {
22 c, err = fileConn(f)
23 if err != nil {
24 err = &OpError{Op: "file", Net: "file+net", Source: nil, Addr: fileAddr(f.Name()), Err: err}
26 return
29 // FileListener returns a copy of the network listener corresponding
30 // to the open file f.
31 // It is the caller's responsibility to close ln when finished.
32 // Closing ln does not affect f, and closing f does not affect ln.
33 func FileListener(f *os.File) (ln Listener, err error) {
34 ln, err = fileListener(f)
35 if err != nil {
36 err = &OpError{Op: "file", Net: "file+net", Source: nil, Addr: fileAddr(f.Name()), Err: err}
38 return
41 // FilePacketConn returns a copy of the packet network connection
42 // corresponding to the open file f.
43 // It is the caller's responsibility to close f when finished.
44 // Closing c does not affect f, and closing f does not affect c.
45 func FilePacketConn(f *os.File) (c PacketConn, err error) {
46 c, err = filePacketConn(f)
47 if err != nil {
48 err = &OpError{Op: "file", Net: "file+net", Source: nil, Addr: fileAddr(f.Name()), Err: err}
50 return