func (c *client) waitOnline(msg *define.Msg) (err error) { // Push the online msg glog.Info("Get a online msg") // Check the msg time if msg.Expired > 0 { if time.Now().UTC().Unix() > msg.Expired { // cancel send the msg glog.Info("Out of time") return } } // Add the msg into cache if msg == nil { err = errors.New("onlines has been close") return } if len(c.onlineCache) > Conf.MaxCacheMsg && Conf.MaxCacheMsg != 0 { err = fmt.Errorf("Online msg is out of range:%v", len(c.onlineCache)) return } mid := c.getOnlineMsgId() if mid == -1 { return } msg.Msg_id = mid msg.Typ = define.ONLINE c.onlineCache[msg.Msg_id] = msg err = c.pushMsg(msg) c.counter++ return }
func (c *client) waitOffline(msg *define.Msg) (err error) { // Check the msg time if msg.Expired > 0 { if time.Now().UTC().Unix() > msg.Expired { // cancel send the msg glog.Info("Out of time.") // TODO Del the offline msg store.Manager.DelOfflineMsg(msg.Id) return } } msg.Msg_id = c.getOnlineMsgId() if msg.Msg_id == -1 { return } c.offline_map[msg.Msg_id] = msg.Id // Push the offline msg glog.Info("Get a offline msg") // Set the msg id err = c.pushOfflineMsg(msg) c.counter++ return }