// Copyright 2014 Mikio Hara. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package tcp

import (
	
	

	
)

var _ net.Conn = &Conn{}

// SetOption sets a socket option.
func ( *Conn) ( tcpopt.Option) error {
	if !.ok() {
		return syscall.EINVAL
	}
	,  := .Marshal()
	if  != nil {
		return &net.OpError{Op: "raw-control", Net: .LocalAddr().Network(), Source: nil, Addr: .LocalAddr(), Err: }
	}
	if  := .setOption(.Level(), .Name(), );  != nil {
		return &net.OpError{Op: "raw-control", Net: .LocalAddr().Network(), Source: nil, Addr: .LocalAddr(), Err: }
	}
	return nil
}

// Option returns a socket option.
func ( *Conn) (,  int,  []byte) (tcpopt.Option, error) {
	if !.ok() || len() == 0 {
		return nil, syscall.EINVAL
	}
	,  := .option(, , )
	if  != nil {
		return nil, &net.OpError{Op: "raw-control", Net: .LocalAddr().Network(), Source: nil, Addr: .LocalAddr(), Err: }
	}
	,  := tcpopt.Parse(, , [:])
	if  != nil {
		return nil, &net.OpError{Op: "raw-control", Net: .LocalAddr().Network(), Source: nil, Addr: .LocalAddr(), Err: }
	}
	return , nil
}

// Buffered returns the number of bytes that can be read from the
// underlying socket read buffer.
// It returns -1 when the platform doesn't support this feature.
func ( *Conn) () int {
	if !.ok() {
		return -1
	}
	return .buffered()
}

// Available returns how many bytes are unused in the underlying
// socket write buffer.
// It returns -1 when the platform doesn't support this feature.
func ( *Conn) () int {
	if !.ok() {
		return -1
	}
	return .available()
}

// OriginalDst returns an original destination address, which is an
// address not modified by intermediate entities such as network
// address and port translators inside the kernel, on the connection.
//
// Only Linux and BSD variants using PF support this feature.
func ( *Conn) () (net.Addr, error) {
	if !.ok() {
		return nil, syscall.EINVAL
	}
	 := .LocalAddr().(*net.TCPAddr)
	,  := .originalDst(, .RemoteAddr().(*net.TCPAddr))
	if  != nil {
		return nil, &net.OpError{Op: "raw-control", Net: .LocalAddr().Network(), Source: nil, Addr: , Err: }
	}
	return , nil
}