code: func (c *Conn) Close() error {
  	// Interlock with Conn.Write above.
  	var x int32
  	for {
  		x = atomic.LoadInt32(&c.activeCall)
  		if x&1 != 0 {
  			return errClosed
  		}
  		if atomic.CompareAndSwapInt32(&c.activeCall, x, x|1) {
  			break
  		}
  	}
  	if x != 0 {
  		// io.Writer and io.Closer should not be used concurrently.
  		// If Close is called while a Write is currently in-flight,
  		// interpret that as a sign that this Close is really just
  		// being used to break the Write and/or clean up resources and
  		// avoid sending the alertCloseNotify, which may block
  		// waiting on handshakeMutex or the c.out mutex.
  		return c.conn.Close()
  	}
  
  	var alertErr error
  
  	c.handshakeMutex.Lock()
  	defer c.handshakeMutex.Unlock()
  	if c.handshakeComplete {
  		alertErr = c.sendAlert(alertCloseNotify)
  	}
  
  	if err := c.conn.Close(); err != nil {
  		return err
  	}
  	return alertErr
  }
docs: // Close closes the connection.