Example #1
0
//----------------------------------------------- user's timer
func timer_work(sess *Session) {
	if sess.Flag&SESS_LOGGED_IN == 0 {
		return
	}

	// SIGTERM check
	if atomic.LoadInt32(&SIGTERM) == 1 {
		sess.Flag |= SESS_KICKED_OUT
		helper.NOTICE("SIGTERM received, user exits.", sess.User.Id, sess.User.Name)
	}

	// limit rate of request per minute
	config := cfg.Get()
	rpm_limit, _ := strconv.ParseFloat(config["rpm_limit"], 32)
	rpm := float64(sess.PacketCount) / float64(time.Now().Unix()-sess.ConnectTime.Unix()) * 60

	if rpm > rpm_limit {
		sess.Flag |= SESS_KICKED_OUT
		helper.ERR("user RPM too high", sess.User.Id, sess.User.Name, "RPM:", rpm)
		return
	}

	// try save the data
	_flush_work(sess)
}
Example #2
0
File: flush.go Project: hycxa/gonet
//------------------------------------------------ save to db
func _flush(sess *Session) {
	if sess.User != nil {
		sess.User.LastSaveTime = time.Now().Unix()
		user_tbl.Set(sess.User)
		helper.NOTICE(sess.User.Id, sess.User.Name, "data flushed")
	}

	// TODO : save all the data in session
	sess.MarkClean()
}
Example #3
0
File: flush.go Project: hycxa/gonet
//------------------------------------------------ data flush control (interval + dirty flag)
func _flush_work(sess *Session) {
	config := cfg.Get()
	fi := config["flush_interval"]
	inter, _ := strconv.Atoi(fi)
	fo := config["flush_ops"]
	ops, _ := strconv.Atoi(fo)

	if sess.DirtyCount() > int32(ops) || (sess.DirtyCount() > 0 && time.Now().Unix()-sess.User.LastSaveTime > int64(inter)) {
		helper.NOTICE("flush dirtycount:", sess.DirtyCount(), "duration(sec):", time.Now().Unix()-sess.User.LastSaveTime)
		_flush(sess)
	}
}