1 // Copyright 2023 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.
12 _ "unsafe" // for go:linkname
15 func fileListener(f *os.File) (Listener, error) {
16 fd, err := newFileFD(f)
20 return &TCPListener{fd: fd}, nil
23 func fileConn(f *os.File) (Conn, error) {
24 fd, err := newFileFD(f)
28 return &TCPConn{conn{fd: fd}}, nil
31 func filePacketConn(f *os.File) (PacketConn, error) { return nil, syscall.ENOPROTOOPT }
33 func newFileFD(f *os.File) (fd *netFD, err error) {
34 pfd := f.PollFD().Copy()
40 filetype, err := fd_fdstat_get_type(pfd.Sysfd)
44 if filetype != syscall.FILETYPE_SOCKET_STREAM {
45 return nil, syscall.ENOTSOCK
47 fd, err = newPollFD(pfd)
51 if err := fd.init(); err != nil {
57 // This helper is implemented in the syscall package. It means we don't have
58 // to redefine the fd_fdstat_get host import or the fdstat struct it
61 //go:linkname fd_fdstat_get_type syscall.fd_fdstat_get_type
62 func fd_fdstat_get_type(fd int) (uint8, error)