func (c *Client) Notify(hs *routing.HTTPSession) routing.HResult { log.D("Notify->%v", "xxx") var addr = hs.R.Header.Get("X-Real-IP") if len(addr) < 1 { addr = hs.R.RemoteAddr } hs.R.ParseForm() var vals = hs.R.Form var sign, sign_type = vals.Get("sign"), vals.Get("sign_type") vals.Del("sign") vals.Del("sign_type") var data = vals.Encode() data, _ = url.QueryUnescape(data) var err = c.Web.Verify(data, sign, sign_type) if err != nil { log.W("Client.Notify recieve bad request from address(%v),err:%v->\nsign_type=%v&sign=%v&%v", addr, err, sign_type, sign, data) hs.W.WriteHeader(400) hs.W.Write([]byte(err.Error())) return routing.HRES_RETURN } log.D("Client.Notify receive verify request from address(%v) by args:\nsign_type=%v&sign=%v&%v\n<-", addr, sign_type, sign, data) err = c.H.OnNotify(c, hs) if err == nil { hs.W.Write([]byte("success")) } else { log.W("Client.Notify call on notify fail with error(%v)", err) hs.W.WriteHeader(400) hs.W.Write([]byte(err.Error())) } return routing.HRES_RETURN }
func PoolWaitNextV(cf CF, name, id string, increase int64, timeout time.Duration) int64 { var tempDelay time.Duration // how long to sleep on accept failure for { next, err := PoolNextV(cf, name, id, increase) if err != nil { if tempDelay == 0 { tempDelay = 5 * time.Millisecond } else { tempDelay *= 2 } if tempDelay > timeout { break } log.W("MDbs next sequence error: %v; retrying in %v", err, tempDelay) time.Sleep(tempDelay) continue } tempDelay = 0 return next } panic("MDbs next sequence time out") }
func (m *MDbs) SelMDb() *MDb { all := len(m.Dbs) if all < 1 { panic("database session list is empty, please add at last one") } tidx := atomic.AddUint32(&m.onum, 1) bidx := int(tidx % uint32(all)) beg := util.Now() for { for i := 0; i < all; i++ { mdb := m.Dbs[(bidx+i)%all] if mdb.IsActive() { atomic.AddUint64(&mdb.Hited, 1) return mdb } } log.W("MDbs all session is not active, it will retry after 1s") time.Sleep(time.Second) if util.Now()-beg > m.Timeout { break } } panic(fmt.Sprintf("MDbs wait database active timeout(%vms)", m.Timeout)) }