// Copyright 2020 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.

//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || windows
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris windows

package net

import (
	
	
	
	
)

// Network file descriptor.
type netFD struct {
	pfd poll.FD

	// immutable until Close
	family      int
	sotype      int
	isConnected bool // handshake completed or use of association with peer
	net         string
	laddr       Addr
	raddr       Addr
}

func ( *netFD) (,  Addr) {
	.laddr = 
	.raddr = 
	runtime.SetFinalizer(, (*netFD).Close)
}

func ( *netFD) () error {
	runtime.SetFinalizer(, nil)
	return .pfd.Close()
}

func ( *netFD) ( int) error {
	 := .pfd.Shutdown()
	runtime.KeepAlive()
	return wrapSyscallError("shutdown", )
}

func ( *netFD) () error {
	return .shutdown(syscall.SHUT_RD)
}

func ( *netFD) () error {
	return .shutdown(syscall.SHUT_WR)
}

func ( *netFD) ( []byte) ( int,  error) {
	,  = .pfd.Read()
	runtime.KeepAlive()
	return , wrapSyscallError(readSyscallName, )
}

func ( *netFD) ( []byte) ( int,  syscall.Sockaddr,  error) {
	, ,  = .pfd.ReadFrom()
	runtime.KeepAlive()
	return , , wrapSyscallError(readFromSyscallName, )
}

func ( *netFD) ( []byte,  []byte,  int) (, ,  int,  syscall.Sockaddr,  error) {
	, , , ,  = .pfd.ReadMsg(, , )
	runtime.KeepAlive()
	return , , , , wrapSyscallError(readMsgSyscallName, )
}

func ( *netFD) ( []byte) ( int,  error) {
	,  = .pfd.Write()
	runtime.KeepAlive()
	return , wrapSyscallError(writeSyscallName, )
}

func ( *netFD) ( []byte,  syscall.Sockaddr) ( int,  error) {
	,  = .pfd.WriteTo(, )
	runtime.KeepAlive()
	return , wrapSyscallError(writeToSyscallName, )
}

func ( *netFD) ( []byte,  []byte,  syscall.Sockaddr) ( int,  int,  error) {
	, ,  = .pfd.WriteMsg(, , )
	runtime.KeepAlive()
	return , , wrapSyscallError(writeMsgSyscallName, )
}

func ( *netFD) ( time.Time) error {
	return .pfd.SetDeadline()
}

func ( *netFD) ( time.Time) error {
	return .pfd.SetReadDeadline()
}

func ( *netFD) ( time.Time) error {
	return .pfd.SetWriteDeadline()
}