xtaci / smux

A Stream Multiplexing Library for golang with least memory usage(TDMA)
MIT License
1.31k stars 196 forks source link

Unnecessary keepalive frames #66

Open sintanial opened 4 years ago

sintanial commented 4 years ago

I think, If data is read from a connection, then there is no point in sending a keepalive frame. It is necessary to send the keepalive frame after some timeout from the last read operation. Because success read means that connection is alive, and keepalive frame in this case unnecessary.

xtaci commented 4 years ago

can you elaborate?

sintanial commented 4 years ago

Currently this code https://github.com/xtaci/smux/blob/master/session.go#L383 send keepalive frame (cmdNOP) every 10 seconds. During intensive data transfer (cmdPSH), keepalive frames(cmdNOP) are not needed. Because the fact of reading data (cmdPSH) already means that the connection is live.

So, I suggest start sending keepalive frames (cmdNOP) after the last successful reading of data.

The simplest solution is replace https://github.com/xtaci/smux/blob/master/session.go#L384 time.Ticker to time.Timer, and after successful reading cdmPSH reset time.Timer (https://golang.org/pkg/time/#Timer.Reset) ;)

xtaci commented 4 years ago

for receiving only connection, it's necessary to send cmdNOP perodically. only 8 bytes in 10 seconds.

sintanial commented 4 years ago

Maybe you are right and this is overkill :)