Skip to content

Commit

Permalink
use unbuffered chan for better timing and memory
Browse files Browse the repository at this point in the history
  • Loading branch information
xtaci committed Mar 8, 2017
1 parent 509975d commit f918e6d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 1 addition & 3 deletions emitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (

var defaultEmitter Emitter

const emitQueue = 2048

func init() {
defaultEmitter.init()
}
Expand All @@ -30,7 +28,7 @@ type (
)

func (e *Emitter) init() {
e.ch = make(chan emitPacket, emitQueue)
e.ch = make(chan emitPacket)
go e.emitTask()
}

Expand Down
4 changes: 3 additions & 1 deletion kcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,9 +665,9 @@ func (kcp *KCP) flush(ackOnly bool) {
return
}

current := currentMs()
// probe window size (if remote window size equals zero)
if kcp.rmt_wnd == 0 {
current := currentMs()
if kcp.probe_wait == 0 {
kcp.probe_wait = IKCP_PROBE_INIT
kcp.ts_probe = current + kcp.probe_wait
Expand Down Expand Up @@ -747,6 +747,7 @@ func (kcp *KCP) flush(ackOnly bool) {

// send new segments
for k := len(kcp.snd_buf) - newSegsCount; k < len(kcp.snd_buf); k++ {
current := currentMs()
segment := &kcp.snd_buf[k]
segment.xmit++
segment.rto = kcp.rx_rto
Expand All @@ -770,6 +771,7 @@ func (kcp *KCP) flush(ackOnly bool) {

// check for retransmissions
for k := 0; k < len(kcp.snd_buf)-newSegsCount; k++ {
current := currentMs()
segment := &kcp.snd_buf[k]
needsend := false
if _itimediff(current, segment.resendts) >= 0 { // RTO
Expand Down

0 comments on commit f918e6d

Please sign in to comment.