package reuseport

import (
	
	

	
)

var fallbackDialer net.Dialer

// Dials using reuseport and then redials normally if that fails.
func reuseDial( context.Context,  *net.TCPAddr, ,  string) ( net.Conn,  error) {
	if  == nil {
		return fallbackDialer.DialContext(, , )
	}

	 := net.Dialer{
		LocalAddr: ,
		Control:   reuseport.Control,
	}

	,  = .DialContext(, , )
	if  == nil {
		return , nil
	}

	if reuseErrShouldRetry() && .Err() == nil {
		// We could have an existing socket open or we could have one
		// stuck in TIME-WAIT.
		log.Debugf("failed to reuse port, will try again with a random port: %s", )
		,  = fallbackDialer.DialContext(, , )
	}
	return , 
}