Skip to content

Commit

Permalink
Rename to use c.lastIn as timestamp for last received client data or …
Browse files Browse the repository at this point in the history
…ping
  • Loading branch information
sandykellagher committed Apr 5, 2023
1 parent 5c5f773 commit d7b2ab5
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions server/client.go
Expand Up @@ -253,7 +253,9 @@ type client struct {
ping pinfo
msgb [msgScratchSize]byte
last time.Time
headers bool
lastIn time.Time

headers bool

rtt time.Duration
rttStart time.Time
Expand Down Expand Up @@ -286,9 +288,8 @@ type rrTracking struct {

// Struct for PING initiation from the server.
type pinfo struct {
tmr *time.Timer
last time.Time
out int
tmr *time.Timer
out int
}

// outbound holds pending data for a socket.
Expand Down Expand Up @@ -1310,7 +1311,7 @@ func (c *client) readLoop(pre []byte) {
// Also update last receive activity for ping sender
if c.in.msgs > 0 || c.in.subs > 0 {
c.last = last
c.ping.last = last
c.lastIn = last
}

if n >= cap(b) {
Expand Down Expand Up @@ -2198,7 +2199,7 @@ func (c *client) processPing() {

// Record this to suppress us sending one if this
// is within a given time interval for activity.
c.ping.last = time.Now()
c.lastIn = time.Now()

// If not a CLIENT, we are done. Also the CONNECT should
// have been received, but make sure it is so before proceeding
Expand Down Expand Up @@ -4572,7 +4573,7 @@ func (c *client) processPingTimer() {
} else {
// If we received client data or a ping from the other side within the PingInterval,
// then there is no need to send a ping.
if delta := now.Sub(c.ping.last); delta < pingInterval && !needRTT {
if delta := now.Sub(c.lastIn); delta < pingInterval && !needRTT {
c.Debugf("Delaying PING due to remote client data or ping %v ago", delta.Round(time.Second))
} else {
sendPing = true
Expand Down

0 comments on commit d7b2ab5

Please sign in to comment.