Пример #1
0
func (this *Tunneld) serveKcp() {
	zbuf := make([]byte, 0)
	if true {
		chks, nxtss := kcp_poll(this.chpool.pool)

		mints := gopp.MinU32(nxtss)
		if mints > 10 && mints != math.MaxUint32 {
			this.kcpNextUpdateWait = int(mints)
			return
		} else {
			this.kcpNextUpdateWait = 10
		}

		for _, ch := range chks {
			if ch.kcp == nil {
				continue
			}

			ch.kcp.Update(uint32(iclock()))

			n := ch.kcp.Recv(zbuf)
			switch n {
			case -3:
				this.processKcpReadyRead(ch)
			case -2: // just empty kcp recv queue
				// errl.Println("kcp recv internal error:", n, this.kcp.PeekSize())
			case -1: // EAGAIN
			default:
				errl.Println("unknown recv:", n)
			}
		}
	}
}
Пример #2
0
func (this *Tunneld) serveKcp() {
	zbuf := make([]byte, 0)
	nxts := make([]uint32, 0)
	chks := make(map[*Channel]bool, 0)
	if true {
		for _, ch := range this.chpool.pool {
			if ch.kcp == nil {
				continue
			}
			curts := uint32(iclock())
			rts := ch.kcp.Check(curts)
			if rts == curts {
				nxts = append(nxts, 10)
				chks[ch] = true
			} else {
				nxts = append(nxts, rts-curts)
			}
		}

		mints := gopp.MinU32(nxts)
		if mints > 10 && mints != math.MaxUint32 {
			this.kcpNextUpdateWait = int(mints)
			return
		} else {
			this.kcpNextUpdateWait = 10
		}

		for _, ch := range this.chpool.pool {
			if ch.kcp == nil {
				continue
			}
			if _, ok := chks[ch]; !ok {
				continue
			}

			ch.kcp.Update(uint32(iclock()))

			n := ch.kcp.Recv(zbuf)
			switch n {
			case -3:
				this.processKcpReadyRead(ch)
			case -2: // just empty kcp recv queue
				// errl.Println("kcp recv internal error:", n, this.kcp.PeekSize())
			case -1: // EAGAIN
			default:
				errl.Println("unknown recv:", n)
			}
		}
	}
}