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 // TCPConn is an implementation of the Conn interface
15 // for TCP network connections.
20 // SetDeadline implements the Conn SetDeadline method.
21 func (c *TCPConn) SetDeadline(t time.Time) error {
25 // SetReadDeadline implements the Conn SetReadDeadline method.
26 func (c *TCPConn) SetReadDeadline(t time.Time) error {
30 // SetWriteDeadline implements the Conn SetWriteDeadline method.
31 func (c *TCPConn) SetWriteDeadline(t time.Time) error {
35 // CloseRead shuts down the reading side of the TCP connection.
36 // Most callers should just use Close.
37 func (c *TCPConn) CloseRead() error {
44 // CloseWrite shuts down the writing side of the TCP connection.
45 // Most callers should just use Close.
46 func (c *TCPConn) CloseWrite() error {
53 // DialTCP connects to the remote address raddr on the network net,
54 // which must be "tcp", "tcp4", or "tcp6". If laddr is not nil, it is used
55 // as the local address for the connection.
56 func DialTCP(net string, laddr, raddr *TCPAddr) (c *TCPConn, err error) {
58 case "tcp", "tcp4", "tcp6":
60 return nil, UnknownNetworkError(net)
63 return nil, &OpError{"dial", net, nil, errMissingAddress}
65 c1, err := dialPlan9(net, laddr, raddr)
69 return &TCPConn{*c1}, nil
72 // TCPListener is a TCP network listener.
73 // Clients should typically use variables of type Listener
74 // instead of assuming TCP.
75 type TCPListener struct {
79 // ListenTCP announces on the TCP address laddr and returns a TCP listener.
80 // Net must be "tcp", "tcp4", or "tcp6".
81 // If laddr has a port of 0, it means to listen on some available port.
82 // The caller can use l.Addr() to retrieve the chosen address.
83 func ListenTCP(net string, laddr *TCPAddr) (l *TCPListener, err error) {
85 case "tcp", "tcp4", "tcp6":
87 return nil, UnknownNetworkError(net)
90 return nil, &OpError{"listen", net, nil, errMissingAddress}
92 l1, err := listenPlan9(net, laddr)
96 return &TCPListener{*l1}, nil