The pingReceiver checks that we've received a message (any message will do, but we expect pings in the absence of other messages) within the last ReceiveTimeout. If not, we close the connection with an ErrTimeout.
()
| 1026 | // but we expect pings in the absence of other messages) within the last |
| 1027 | // ReceiveTimeout. If not, we close the connection with an ErrTimeout. |
| 1028 | func (c *rawConnection) pingReceiver() { |
| 1029 | ticker := time.NewTicker(ReceiveTimeout / 2) |
| 1030 | defer ticker.Stop() |
| 1031 | |
| 1032 | for { |
| 1033 | select { |
| 1034 | case <-ticker.C: |
| 1035 | d := time.Since(c.cr.Last()) |
| 1036 | if d > ReceiveTimeout { |
| 1037 | l.Debugln(c.deviceID, "ping timeout", d) |
| 1038 | c.internalClose(ErrTimeout) |
| 1039 | } |
| 1040 | |
| 1041 | l.Debugln(c.deviceID, "last read within", d) |
| 1042 | |
| 1043 | case <-c.closed: |
| 1044 | return |
| 1045 | } |
| 1046 | } |
| 1047 | } |
| 1048 | |
| 1049 | type Statistics struct { |
| 1050 | At time.Time `json:"at"` |