github.com/xmplusdev/xmcore@v1.8.11-0.20240412132628-5518b55526af/transport/internet/udp/dialer.go (about)

     1  package udp
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/xmplusdev/xmcore/common"
     7  	"github.com/xmplusdev/xmcore/common/net"
     8  	"github.com/xmplusdev/xmcore/transport/internet"
     9  	"github.com/xmplusdev/xmcore/transport/internet/stat"
    10  )
    11  
    12  func init() {
    13  	common.Must(internet.RegisterTransportDialer(protocolName,
    14  		func(ctx context.Context, dest net.Destination, streamSettings *internet.MemoryStreamConfig) (stat.Connection, error) {
    15  			var sockopt *internet.SocketConfig
    16  			if streamSettings != nil {
    17  				sockopt = streamSettings.SocketSettings
    18  			}
    19  			conn, err := internet.DialSystem(ctx, dest, sockopt)
    20  			if err != nil {
    21  				return nil, err
    22  			}
    23  			// TODO: handle dialer options
    24  			return stat.Connection(conn), nil
    25  		}))
    26  }