github.com/remobjects/goldbaselibrary@v0.0.0-20230924164425-d458680a936b/Source/Gold/net/tcpsock_plan9.go (about) 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 tc := newTCPConn(fd) 48 if ln.lc.KeepAlive >= 0 { 49 setKeepAlive(fd, true) 50 ka := ln.lc.KeepAlive 51 if ln.lc.KeepAlive == 0 { 52 ka = defaultTCPKeepAlive 53 } 54 setKeepAlivePeriod(fd, ka) 55 } 56 return tc, nil 57 } 58 59 func (ln *TCPListener) close() error { 60 if err := ln.fd.pfd.Close(); err != nil { 61 return err 62 } 63 if _, err := ln.fd.ctl.WriteString("hangup"); err != nil { 64 ln.fd.ctl.Close() 65 return err 66 } 67 if err := ln.fd.ctl.Close(); err != nil { 68 return err 69 } 70 return nil 71 } 72 73 func (ln *TCPListener) file() (*os.File, error) { 74 f, err := ln.dup() 75 if err != nil { 76 return nil, err 77 } 78 return f, nil 79 } 80 81 func (sl *sysListener) listenTCP(ctx context.Context, laddr *TCPAddr) (*TCPListener, error) { 82 fd, err := listenPlan9(ctx, sl.network, laddr) 83 if err != nil { 84 return nil, err 85 } 86 return &TCPListener{fd: fd, lc: sl.ListenConfig}, nil 87 }