The Go Programming Language

Source file src/pkg/net/pipe.go

     1	package net
     2	
     3	import (
     4		"io"
     5		"os"
     6	)
     7	
     8	// Pipe creates a synchronous, in-memory, full duplex
     9	// network connection; both ends implement the Conn interface.
    10	// Reads on one end are matched with writes on the other,
    11	// copying data directly between the two; there is no internal
    12	// buffering.
    13	func Pipe() (Conn, Conn) {
    14		r1, w1 := io.Pipe()
    15		r2, w2 := io.Pipe()
    16	
    17		return &pipe{r1, w2}, &pipe{r2, w1}
    18	}
    19	
    20	type pipe struct {
    21		*io.PipeReader
    22		*io.PipeWriter
    23	}
    24	
    25	type pipeAddr int
    26	
    27	func (pipeAddr) Network() string {
    28		return "pipe"
    29	}
    30	
    31	func (pipeAddr) String() string {
    32		return "pipe"
    33	}
    34	
    35	func (p *pipe) Close() os.Error {
    36		err := p.PipeReader.Close()
    37		err1 := p.PipeWriter.Close()
    38		if err == nil {
    39			err = err1
    40		}
    41		return err
    42	}
    43	
    44	func (p *pipe) LocalAddr() Addr {
    45		return pipeAddr(0)
    46	}
    47	
    48	func (p *pipe) RemoteAddr() Addr {
    49		return pipeAddr(0)
    50	}
    51	
    52	func (p *pipe) SetTimeout(nsec int64) os.Error {
    53		return os.NewError("net.Pipe does not support timeouts")
    54	}
    55	
    56	func (p *pipe) SetReadTimeout(nsec int64) os.Error {
    57		return os.NewError("net.Pipe does not support timeouts")
    58	}
    59	
    60	func (p *pipe) SetWriteTimeout(nsec int64) os.Error {
    61		return os.NewError("net.Pipe does not support timeouts")
    62	}

release.r60.3. Except as noted, this content is licensed under a Creative Commons Attribution 3.0 License.