in conn.go [255:320]
func newConn(netConn net.Conn, opts *ConnOptions) (*Conn, error) {
c := &Conn{
dialer: defaultDialer{},
net: netConn,
maxFrameSize: defaultMaxFrameSize,
peerMaxFrameSize: defaultMaxFrameSize,
channelMax: defaultMaxSessions - 1, // -1 because channel-max starts at zero
idleTimeout: defaultIdleTimeout,
containerID: shared.RandString(40),
done: make(chan struct{}),
rxtxExit: make(chan struct{}),
rxDone: make(chan struct{}),
txFrame: make(chan frameEnvelope),
txDone: make(chan struct{}),
sessionsByChannel: map[uint16]*Session{},
writeTimeout: defaultWriteTimeout,
}
// apply options
if opts == nil {
opts = &ConnOptions{}
}
if opts.WriteTimeout > 0 {
c.writeTimeout = opts.WriteTimeout
} else if opts.WriteTimeout < 0 {
c.writeTimeout = 0
}
if opts.ContainerID != "" {
c.containerID = opts.ContainerID
}
if opts.HostName != "" {
c.hostname = opts.HostName
}
if opts.IdleTimeout > 0 {
c.idleTimeout = opts.IdleTimeout
} else if opts.IdleTimeout < 0 {
c.idleTimeout = 0
}
if opts.MaxFrameSize > 0 && opts.MaxFrameSize < 512 {
return nil, fmt.Errorf("invalid MaxFrameSize value %d", opts.MaxFrameSize)
} else if opts.MaxFrameSize > 512 {
c.maxFrameSize = opts.MaxFrameSize
}
if opts.MaxSessions > 0 {
c.channelMax = opts.MaxSessions
}
if opts.SASLType != nil {
if err := opts.SASLType(c); err != nil {
return nil, err
}
}
if opts.Properties != nil {
c.properties = make(map[encoding.Symbol]any)
for key, val := range opts.Properties {
c.properties[encoding.Symbol(key)] = val
}
}
if opts.TLSConfig != nil {
c.tlsConfig = opts.TLSConfig.Clone()
}
if opts.dialer != nil {
c.dialer = opts.dialer
}
return c, nil
}