...
Run Format

Source file src/net/tcpsock_plan9.go

Documentation: net

     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.
     4  
     5  package net
     6  
     7  import (
     8  	"context"
     9  	"io"
    10  	"os"
    11  )
    12  
    13  func (c *TCPConn) readFrom(r io.Reader) (int64, error) {
    14  	return genericReadFrom(c, r)
    15  }
    16  
    17  func (sd *sysDialer) dialTCP(ctx context.Context, laddr, raddr *TCPAddr) (*TCPConn, error) {
    18  	if testHookDialTCP != nil {
    19  		return testHookDialTCP(ctx, sd.network, laddr, raddr)
    20  	}
    21  	return sd.doDialTCP(ctx, laddr, raddr)
    22  }
    23  
    24  func (sd *sysDialer) doDialTCP(ctx context.Context, laddr, raddr *TCPAddr) (*TCPConn, error) {
    25  	switch sd.network {
    26  	case "tcp", "tcp4", "tcp6":
    27  	default:
    28  		return nil, UnknownNetworkError(sd.network)
    29  	}
    30  	if raddr == nil {
    31  		return nil, errMissingAddress
    32  	}
    33  	fd, err := dialPlan9(ctx, sd.network, laddr, raddr)
    34  	if err != nil {
    35  		return nil, err
    36  	}
    37  	return newTCPConn(fd), nil
    38  }
    39  
    40  func (ln *TCPListener) ok() bool { return ln != nil && ln.fd != nil && ln.fd.ctl != nil }
    41  
    42  func (ln *TCPListener) accept() (*TCPConn, error) {
    43  	fd, err := ln.fd.acceptPlan9()
    44  	if err != nil {
    45  		return nil, err
    46  	}
    47  	return newTCPConn(fd), nil
    48  }
    49  
    50  func (ln *TCPListener) close() error {
    51  	if err := ln.fd.pfd.Close(); err != nil {
    52  		return err
    53  	}
    54  	if _, err := ln.fd.ctl.WriteString("hangup"); err != nil {
    55  		ln.fd.ctl.Close()
    56  		return err
    57  	}
    58  	if err := ln.fd.ctl.Close(); err != nil {
    59  		return err
    60  	}
    61  	return nil
    62  }
    63  
    64  func (ln *TCPListener) file() (*os.File, error) {
    65  	f, err := ln.dup()
    66  	if err != nil {
    67  		return nil, err
    68  	}
    69  	return f, nil
    70  }
    71  
    72  func (sl *sysListener) listenTCP(ctx context.Context, laddr *TCPAddr) (*TCPListener, error) {
    73  	fd, err := listenPlan9(ctx, sl.network, laddr)
    74  	if err != nil {
    75  		return nil, err
    76  	}
    77  	return &TCPListener{fd}, nil
    78  }
    79  

View as plain text