...

Source file src/net/file.go

     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.
     4	
     5	package net
     6	
     7	import "os"
     8	
     9	// BUG(mikio): On JS, NaCl and Windows, the FileConn, FileListener and
    10	// FilePacketConn functions are not implemented.
    11	
    12	type fileAddr string
    13	
    14	func (fileAddr) Network() string  { return "file+net" }
    15	func (f fileAddr) String() string { return string(f) }
    16	
    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}
    25		}
    26		return
    27	}
    28	
    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}
    37		}
    38		return
    39	}
    40	
    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}
    49		}
    50		return
    51	}
    52	

View as plain text