Skip to content

Commit 0c7c8c6

Browse files
committed
set inner recv chan length 1, emitter chan length to 1
1 parent 0df987f commit 0c7c8c6

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

emitter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type (
2828
)
2929

3030
func (e *Emitter) init() {
31-
e.ch = make(chan emitPacket)
31+
e.ch = make(chan emitPacket, 1)
3232
go e.emitTask()
3333
}
3434

sess.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ const (
3636
// maximum packet size
3737
mtuLimit = 1500
3838

39-
// packet receiving channel limit
40-
rxQueueLimit = 2048
41-
4239
// FEC keeps rxFECMulti* (dataShard+parityShard) ordered packets in memory
4340
rxFECMulti = 3
4441
)
@@ -618,7 +615,7 @@ func (s *UDPSession) receiver(ch chan []byte) {
618615

619616
// read loop for client session
620617
func (s *UDPSession) readLoop() {
621-
chPacket := make(chan []byte, rxQueueLimit)
618+
chPacket := make(chan []byte, 1)
622619
go s.receiver(chPacket)
623620

624621
for {
@@ -677,7 +674,7 @@ type (
677674

678675
// monitor incoming data for all connections of server
679676
func (l *Listener) monitor() {
680-
chPacket := make(chan inPacket, rxQueueLimit)
677+
chPacket := make(chan inPacket, 1)
681678
go l.receiver(chPacket)
682679
for {
683680
select {
@@ -741,7 +738,10 @@ func (l *Listener) receiver(ch chan inPacket) {
741738
for {
742739
data := xmitBuf.Get().([]byte)[:mtuLimit]
743740
if n, from, err := l.conn.ReadFrom(data); err == nil && n >= l.headerSize+IKCP_OVERHEAD {
744-
ch <- inPacket{from, data[:n]}
741+
select {
742+
case ch <- inPacket{from, data[:n]}:
743+
case <-l.die:
744+
}
745745
} else if err != nil {
746746
return
747747
} else {

0 commit comments

Comments
 (0)