This commit is contained in:
esrrhs 2019-10-26 20:39:41 +08:00
parent c923db7d8a
commit c90545eaf6
2 changed files with 51 additions and 20 deletions

View File

@ -225,14 +225,8 @@ func (fm *FrameMgr) processRecvList(tmpreq map[int32]int, tmpack map[int32]int,
func (fm *FrameMgr) addToRecvWin(rf *Frame) bool { func (fm *FrameMgr) addToRecvWin(rf *Frame) bool {
begin := fm.recvid if !fm.isIdInRange((int)(rf.Id), FRAME_MAX_ID) {
end := fm.recvid + fm.windowsize loggo.Debug("recv frame not in range %d %d", rf.Id, fm.recvid)
id := (int)(rf.Id)
if id < begin {
id += FRAME_MAX_ID
}
if id > end || id < begin {
loggo.Debug("recv frame not in range %d %d %d", begin, end, id)
return false return false
} }
@ -247,7 +241,7 @@ func (fm *FrameMgr) addToRecvWin(rf *Frame) bool {
for e := fm.recvwin.Front(); e != nil; e = e.Next() { for e := fm.recvwin.Front(); e != nil; e = e.Next() {
f := e.Value.(*Frame) f := e.Value.(*Frame)
loggo.Debug("start insert recv win %d %d %d", fm.recvid, rf.Id, f.Id) loggo.Debug("start insert recv win %d %d %d", fm.recvid, rf.Id, f.Id)
if fm.compareId(rf, f) < 0 { if fm.compareId((int)(rf.Id), (int)(f.Id)) < 0 {
fm.recvwin.InsertBefore(rf, e) fm.recvwin.InsertBefore(rf, e)
loggo.Debug("insert recv win %d %d before %d", rf.Id, len(rf.Data), f.Id) loggo.Debug("insert recv win %d %d before %d", rf.Id, len(rf.Data), f.Id)
return true return true
@ -259,10 +253,8 @@ func (fm *FrameMgr) addToRecvWin(rf *Frame) bool {
return true return true
} }
func (fm *FrameMgr) compareId(lf *Frame, rf *Frame) int { func (fm *FrameMgr) compareId(l int, r int) int {
l := (int)(lf.Id)
r := (int)(rf.Id)
if l < fm.recvid { if l < fm.recvid {
l += FRAME_MAX_ID l += FRAME_MAX_ID
} }
@ -310,7 +302,7 @@ func (fm *FrameMgr) combineWindowToRecvBuffer() {
reqtmp := make(map[int]int) reqtmp := make(map[int]int)
e := fm.recvwin.Front() e := fm.recvwin.Front()
id = fm.recvid id = fm.recvid
for len(reqtmp) < fm.windowsize && e != nil { for len(reqtmp) < fm.windowsize && len(reqtmp)*4 < FRAME_MAX_SIZE/2 && e != nil {
f := e.Value.(*Frame) f := e.Value.(*Frame)
loggo.Debug("start add req id %d %d %d", fm.recvid, f.Id, id) loggo.Debug("start add req id %d %d %d", fm.recvid, f.Id, id)
if f.Id != (int32)(id) { if f.Id != (int32)(id) {
@ -392,3 +384,18 @@ func (fm *FrameMgr) processPong(f *Frame) {
loggo.Debug("recv pong %d %d", rtt, fm.rttms) loggo.Debug("recv pong %d %d", rtt, fm.rttms)
} }
} }
func (fm *FrameMgr) isIdInRange(id int, maxid int) bool {
begin := fm.recvid
end := fm.recvid + fm.windowsize
if end >= maxid {
if id >= 0 && id < end-maxid {
return true
}
end = maxid
}
if id >= begin && id < end {
return true
}
return false
}

View File

@ -25,30 +25,54 @@ func Test0001(t *testing.T) {
fmt.Println("my1 = ", my1) fmt.Println("my1 = ", my1)
fm := FrameMgr{} fm := FrameMgr{}
fm.recvid = 0 fm.recvid = 4
fm.windowsize = 100 fm.windowsize = 100
lr := &Frame{} lr := &Frame{}
rr := &Frame{} rr := &Frame{}
lr.Id = 1 lr.Id = 1
rr.Id = 2 rr.Id = 4
fmt.Println("fm.compareId(lr, rr) = ", fm.compareId(lr, rr)) fmt.Println("fm.compareId(lr, rr) = ", fm.compareId((int)(lr.Id), (int)(rr.Id)))
lr.Id = 99 lr.Id = 99
rr.Id = 8 rr.Id = 8
fmt.Println("fm.compareId(lr, rr) = ", fm.compareId(lr, rr)) fmt.Println("fm.compareId(lr, rr) = ", fm.compareId((int)(lr.Id), (int)(rr.Id)))
fm.recvid = 9000 fm.recvid = 9000
lr.Id = 9998 lr.Id = 9998
rr.Id = 9999 rr.Id = 9999
fmt.Println("fm.compareId(lr, rr) = ", fm.compareId(lr, rr)) fmt.Println("fm.compareId(lr, rr) = ", fm.compareId((int)(lr.Id), (int)(rr.Id)))
fm.recvid = 9000 fm.recvid = 9000
lr.Id = 9998 lr.Id = 9998
rr.Id = 8 rr.Id = 8
fmt.Println("fm.compareId(lr, rr) = ", fm.compareId(lr, rr)) fmt.Println("fm.compareId(lr, rr) = ", fm.compareId((int)(lr.Id), (int)(rr.Id)))
fm.recvid = 0 fm.recvid = 0
lr.Id = 9998 lr.Id = 9998
rr.Id = 8 rr.Id = 8
fmt.Println("fm.compareId(lr, rr) = ", fm.compareId(lr, rr)) fmt.Println("fm.compareId(lr, rr) = ", fm.compareId((int)(lr.Id), (int)(rr.Id)))
fm.recvid = 0
fm.windowsize = 5
fmt.Println("fm.isIdInRange = ", fm.isIdInRange(4, 10))
fm.recvid = 0
fm.windowsize = 5
fmt.Println("fm.isIdInRange = ", fm.isIdInRange(5, 10))
fm.recvid = 4
fm.windowsize = 5
fmt.Println("fm.isIdInRange = ", fm.isIdInRange(1, 10))
fm.recvid = 7
fm.windowsize = 5
fmt.Println("fm.isIdInRange = ", fm.isIdInRange(1, 10))
fm.recvid = 7
fm.windowsize = 5
fmt.Println("fm.isIdInRange = ", fm.isIdInRange(2, 10))
fm.recvid = 7
fm.windowsize = 5
fmt.Println("fm.isIdInRange = ", fm.isIdInRange(9, 10))
} }