code: func (c *Client) processConnack(connack *packet.Connack) error {
  	// check state
  	if atomic.LoadUint32(&c.state) != clientConnecting {
  		return nil // ignore wrongly sent Connack packet
  	}
  
  	// set state
  	atomic.StoreUint32(&c.state, clientConnacked)
  
  	// fill future
  	c.connectFuture.Data.Store(sessionPresentKey, connack.SessionPresent)
  	c.connectFuture.Data.Store(returnCodeKey, connack.ReturnCode)
  
  	// return connection denied error and close connection if not accepted
  	if connack.ReturnCode != packet.ConnectionAccepted {
  		err := c.die(ErrClientConnectionDenied, true, false)
  		c.connectFuture.Cancel()
  		return err
  	}
  
  	// set state to connected
  	atomic.StoreUint32(&c.state, clientConnected)
  
  	// complete future
  	c.connectFuture.Complete()
  
  	// retrieve stored packets
  	packets, err := c.Session.AllPackets(session.Outgoing)
  	if err != nil {
  		return c.die(err, true, false)
  	}
  
  	// resend stored packets
  	for _, pkt := range packets {
  		// check for publish packets
  		publish, ok := pkt.(*packet.Publish)
  		if ok {
  			// set the dup flag on a publish packet
  			publish.Dup = true
  		}
  
  		// resend packet
  		err = c.send(pkt, true)
  		if err != nil {
  			return c.die(err, false, false)
  		}
  	}
  
  	return nil
  }
docs: // handle the incoming Connack packet