additional check for nil conn
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
c00b8c7ae0
commit
e1d11c19bb
@ -22,6 +22,10 @@ var (
|
|||||||
|
|
||||||
// Connect handshake with remote server using underlining net.Conn
|
// Connect handshake with remote server using underlining net.Conn
|
||||||
func Connect(ctx context.Context, c net.Conn, cfg *ClientConfig) (*ClientConn, error) {
|
func Connect(ctx context.Context, c net.Conn, cfg *ClientConfig) (*ClientConn, error) {
|
||||||
|
if c == nil {
|
||||||
|
return nil, fmt.Errorf("passed invalid net.Conn")
|
||||||
|
}
|
||||||
|
|
||||||
conn, err := NewClientConn(c, cfg)
|
conn, err := NewClientConn(c, cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
conn.Close()
|
conn.Close()
|
||||||
@ -220,6 +224,7 @@ func NewClientConn(c net.Conn, cfg *ClientConfig) (*ClientConn, error) {
|
|||||||
if len(cfg.Encodings) == 0 {
|
if len(cfg.Encodings) == 0 {
|
||||||
return nil, fmt.Errorf("client can't handle encodings")
|
return nil, fmt.Errorf("client can't handle encodings")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &ClientConn{
|
return &ClientConn{
|
||||||
c: c,
|
c: c,
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
|
Loading…
Reference in New Issue
Block a user