示例#1
0
文件: tunneld.go 项目: kitech/toxtun
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
文件: tunneld.go 项目: kitech/toxsh
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)
			}
		}
	}
}