diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-16 19:23:18 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-16 19:23:18 +0000 |
commit | 43a123c1ae6613b3efeed291fa552ecd909d3acf (patch) | |
tree | fd92518b7024bc74031f78a1cf9e454b65e73665 /src/net/tcpsock_plan9.go | |
parent | Initial commit. (diff) | |
download | golang-1.20-43a123c1ae6613b3efeed291fa552ecd909d3acf.tar.xz golang-1.20-43a123c1ae6613b3efeed291fa552ecd909d3acf.zip |
Adding upstream version 1.20.14.upstream/1.20.14upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/net/tcpsock_plan9.go | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/net/tcpsock_plan9.go b/src/net/tcpsock_plan9.go new file mode 100644 index 0000000..d55948f --- /dev/null +++ b/src/net/tcpsock_plan9.go @@ -0,0 +1,86 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package net + +import ( + "context" + "io" + "os" +) + +func (c *TCPConn) readFrom(r io.Reader) (int64, error) { + return genericReadFrom(c, r) +} + +func (sd *sysDialer) dialTCP(ctx context.Context, laddr, raddr *TCPAddr) (*TCPConn, error) { + if h := sd.testHookDialTCP; h != nil { + return h(ctx, sd.network, laddr, raddr) + } + if h := testHookDialTCP; h != nil { + return h(ctx, sd.network, laddr, raddr) + } + return sd.doDialTCP(ctx, laddr, raddr) +} + +func (sd *sysDialer) doDialTCP(ctx context.Context, laddr, raddr *TCPAddr) (*TCPConn, error) { + switch sd.network { + case "tcp4": + // Plan 9 doesn't complain about [::]:0->127.0.0.1, so it's up to us. + if laddr != nil && len(laddr.IP) != 0 && laddr.IP.To4() == nil { + return nil, &AddrError{Err: "non-IPv4 local address", Addr: laddr.String()} + } + case "tcp", "tcp6": + default: + return nil, UnknownNetworkError(sd.network) + } + if raddr == nil { + return nil, errMissingAddress + } + fd, err := dialPlan9(ctx, sd.network, laddr, raddr) + if err != nil { + return nil, err + } + return newTCPConn(fd, sd.Dialer.KeepAlive, testHookSetKeepAlive), nil +} + +func (ln *TCPListener) ok() bool { return ln != nil && ln.fd != nil && ln.fd.ctl != nil } + +func (ln *TCPListener) accept() (*TCPConn, error) { + fd, err := ln.fd.acceptPlan9() + if err != nil { + return nil, err + } + return newTCPConn(fd, ln.lc.KeepAlive, nil), nil +} + +func (ln *TCPListener) close() error { + if err := ln.fd.pfd.Close(); err != nil { + return err + } + if _, err := ln.fd.ctl.WriteString("hangup"); err != nil { + ln.fd.ctl.Close() + return err + } + if err := ln.fd.ctl.Close(); err != nil { + return err + } + return nil +} + +func (ln *TCPListener) file() (*os.File, error) { + f, err := ln.dup() + if err != nil { + return nil, err + } + return f, nil +} + +func (sl *sysListener) listenTCP(ctx context.Context, laddr *TCPAddr) (*TCPListener, error) { + fd, err := listenPlan9(ctx, sl.network, laddr) + if err != nil { + return nil, err + } + return &TCPListener{fd: fd, lc: sl.ListenConfig}, nil +} |