// expireMsgs ensures that messages don't stay in the log longer than the
// limit's MaxAge.
978530
func (ms *MemoryMsgStore) expireMsgs() {
	ms.Lock()
	defer ms.Unlock()
	if ms.closed {
		ms.wg.Done()
		return
	}

	now := time.Now().UnixNano()
	maxAge := int64(ms.limits.MaxAge)
	for {
		m, ok := ms.msgs[ms.first]
		if !ok {
			if ms.first < ms.last {
				ms.first++
				continue
			}
			ms.ageTimer = nil
			ms.wg.Done()
			return
		}
		elapsed := now - m.Timestamp
		if elapsed >= maxAge {
			ms.removeFirstMsg()
		} else {
			if elapsed < 0 {
				ms.ageTimer.Reset(time.Duration(m.Timestamp - now + maxAge))
			} else {
				ms.ageTimer.Reset(time.Duration(maxAge - elapsed))
			}
			return
		}
	}
}
560075
func (conn *Conn) Privmsg(t, msg string) {
	prefix := PRIVMSG + " " + t + " :"
	for _, s := range splitMessage(msg, conn.cfg.SplitLen) {
		conn.Raw(prefix + s)
	}
}
109122
func (ms *MemoryMsgStore) LastMsg() (*pb.MsgProto, error) {
	ms.RLock()
	m := ms.msgs[ms.last]
	ms.RUnlock()
	return m, nil
}
785648
func (a *SetCookieArgs) SetExpires(expires TimeSinceEpoch) *SetCookieArgs {
	a.Expires = expires
	return a
}
289720
func (q *queue) ExpireHeaders(timeout time.Duration) map[string]int {
	q.lock.Lock()
	defer q.lock.Unlock()

	return q.expire(timeout, q.headerPendPool, q.headerTaskQueue, headerTimeoutMeter)
}
1150613
func (gms *genericMsgStore) LastSequence() (uint64, error) {
	gms.RLock()
	last := gms.last
	gms.RUnlock()
	return last, nil
}
110468
func (z *runContainer16) EncodeMsg(en *msgp.Writer) (err error) {
	// map header, size 2
	// write "iv"
	err = en.Append(0x82, 0xa2, 0x69, 0x76)
	if err != nil {
		return err
	}
	err = en.WriteArrayHeader(uint32(len(z.iv)))
	if err != nil {
		return
	}
	for zxpk := range z.iv {
		// map header, size 2
		// write "start"
		err = en.Append(0x82, 0xa5, 0x73, 0x74, 0x61, 0x72, 0x74)
		if err != nil {
			return err
		}
		err = en.WriteUint16(z.iv[zxpk].start)
		if err != nil {
			return
		}
		// write "last"
		err = en.Append(0xa4, 0x6c, 0x61, 0x73, 0x74)
		if err != nil {
			return err
		}
		err = en.WriteUint16(z.iv[zxpk].last())
		if err != nil {
			return
		}
	}
	// write "card"
	err = en.Append(0xa4, 0x63, 0x61, 0x72, 0x64)
	if err != nil {
		return err
	}
	err = en.WriteInt64(z.card)
	if err != nil {
		return
	}
	return
}
706418
func (*MsgCodec) EncodeMsg(msg api.Message, msgID uint16) (data []byte, err error) {
	if msg == nil {
		return nil, errors.New("nil message passed in")
	}

	// try to recover panic which might possibly occur in struc.Pack call
	defer func() {
		if r := recover(); r != nil {
			var ok bool
			if err, ok = r.(error); !ok {
				err = fmt.Errorf("%v", r)
			}
			err = fmt.Errorf("panic occurred: %v", err)
		}
	}()

	var header interface{}

	// encode message header
	switch msg.GetMessageType() {
	case api.RequestMessage:
		header = &VppRequestHeader{VlMsgID: msgID}
	case api.ReplyMessage:
		header = &VppReplyHeader{VlMsgID: msgID}
	case api.EventMessage:
		header = &VppEventHeader{VlMsgID: msgID}
	default:
		header = &VppOtherHeader{VlMsgID: msgID}
	}

	buf := new(bytes.Buffer)

	// encode message header
	if err := struc.Pack(buf, header); err != nil {
		return nil, fmt.Errorf("failed to encode message header: %+v, error: %v", header, err)
	}

	// encode message content
	if reflect.TypeOf(msg).Elem().NumField() > 0 {
		if err := struc.Pack(buf, msg); err != nil {
			return nil, fmt.Errorf("failed to encode message data: %+v, error: %v", data, err)
		}
	}

	return buf.Bytes(), nil
}
893358
func (z *containerSerz) EncodeMsg(en *msgp.Writer) (err error) {
	// map header, size 2
	// write "t"
	err = en.Append(0x82, 0xa1, 0x74)
	if err != nil {
		return err
	}
	err = en.WriteUint8(uint8(z.t))
	if err != nil {
		return
	}
	// write "r"
	err = en.Append(0xa1, 0x72)
	if err != nil {
		return err
	}
	err = z.r.EncodeMsg(en)
	if err != nil {
		return
	}
	return
}
934021
func (w *FileLogWriter) WriteMsg(msg string, level int) error {
	if level > w.Level {
		return nil
	}
	n := 24 + len(msg) // 24 stand for the length "2013/06/23 21:00:22 [T] "
	w.docheck(n)
	w.Logger.Println(msg)
	return nil
}
1355813
func (z Person) EncodeMsg(en *msgp.Writer) (err error) {
	// map header, size 2
	// write "first"
	err = en.Append(0x82, 0xa5, 0x66, 0x69, 0x72, 0x73, 0x74)
	if err != nil {
		return
	}
	err = en.WriteString(z.First)
	if err != nil {
		return
	}
	// write "last"
	err = en.Append(0xa4, 0x6c, 0x61, 0x73, 0x74)
	if err != nil {
		return
	}
	err = en.WriteString(z.Last)
	if err != nil {
		return
	}
	return
}
341560
func (s *Store) expirer() {
	defer s.wg.Done()

	ticker := time.NewTicker(s.ExpiryCheckInterval)
	defer ticker.Stop()

	for {
		// Wait for next check or for close signal.
		select {
		case <-s.closing:
			return
		case <-ticker.C:
		}

		// Check all instances for expiration.
		if err := s.EnforceExpiry(); err != nil && err != raft.ErrNotLeader {
			s.logger.Printf("enforce expiry: %s", err)
		}
	}
}
473581
func (s *UpdateApiKeyInput) SetExpires(v int64) *UpdateApiKeyInput {
	s.Expires = &v
	return s
}
15928
func (err Error) WithMsg(msgs ...string) *Error {
	if len(msgs) > 0 {
		err.Msg = strings.Join(msgs, ", ")
	}
	return &err
}
809937
func (z *IndexFindByTagResp) EncodeMsg(en *msgp.Writer) (err error) {
	// map header, size 1
	// write "Metrics"
	err = en.Append(0x81, 0xa7, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73)
	if err != nil {
		return
	}
	err = en.WriteArrayHeader(uint32(len(z.Metrics)))
	if err != nil {
		err = msgp.WrapError(err, "Metrics")
		return
	}
	for za0001 := range z.Metrics {
		err = z.Metrics[za0001].EncodeMsg(en)
		if err != nil {
			err = msgp.WrapError(err, "Metrics", za0001)
			return
		}
	}
	return
}
811535
func cookieExpires(maxAge int) (time.Time, bool) {
	if maxAge > 0 {
		d := time.Duration(maxAge) * time.Second
		return time.Now().Add(d), true
	} else if maxAge < 0 {
		return time.Unix(1, 0), true // first second of the epoch
	}
	return time.Time{}, false
}
893048
func (z *IterGen) MarshalMsg(b []byte) (o []byte, err error) {
	o = msgp.Require(b, z.Msgsize())
	// map header, size 3
	// string "T0"
	o = append(o, 0x83, 0xa2, 0x54, 0x30)
	o = msgp.AppendUint32(o, z.T0)
	// string "IntervalHint"
	o = append(o, 0xac, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x76, 0x61, 0x6c, 0x48, 0x69, 0x6e, 0x74)
	o = msgp.AppendUint32(o, z.IntervalHint)
	// string "B"
	o = append(o, 0xa1, 0x42)
	o = msgp.AppendBytes(o, z.B)
	return
}