2
0

Merge branch 'master' into improve_logging

This commit is contained in:
Nikolay Pavlovich
2022-09-04 02:09:49 +03:00
committed by GitHub
4 changed files with 15 additions and 12 deletions
+5 -3
View File
@@ -2,6 +2,8 @@
# recws
***This is fork of [recws-org/recws](https://github.com/recws-org/recws) with some fixes***
Reconnecting WebSocket is a websocket client based on [gorilla/websocket](https://github.com/gorilla/websocket) that will automatically reconnect if the connection is dropped - thread safe!
[![Build Status](https://travis-ci.com/recws-org/recws.svg?branch=master)](https://travis-ci.com/recws-org/recws)
@@ -12,7 +14,7 @@ Reconnecting WebSocket is a websocket client based on [gorilla/websocket](https:
## Installation
```bash
go get github.com/recws-org/recws
go get github.com/nikepan/recws
```
## Sponsors
@@ -21,8 +23,8 @@ go get github.com/recws-org/recws
## Logo
- Logo by [Anastasia Marx](https://www.behance.net/AnastasiaMarx)
- Gopher by [Gophers](https://github.com/egonelbre/gophers)
- Logo by [Anastasia Marx](https://www.behance.net/AnastasiaMarx)
- Gopher by [Gophers](https://github.com/egonelbre/gophers)
## License
+2 -1
View File
@@ -2,9 +2,10 @@ package main
import (
"context"
"github.com/recws-org/recws"
"log"
"time"
"github.com/nikepan/recws"
)
func main() {
+2 -2
View File
@@ -1,6 +1,6 @@
module github.com/recws-org/recws
module github.com/nikepan/recws
go 1.17
go 1.18
require (
github.com/gorilla/websocket v1.4.2
+6 -6
View File
@@ -97,13 +97,12 @@ func (rc *RecConn) getConn() *websocket.Conn {
// Close closes the underlying network connection without
// sending or waiting for a close frame.
func (rc *RecConn) Close() {
if rc.getConn() != nil {
rc.mu.Lock()
rc.mu.Lock()
if rc.Conn != nil {
rc.Conn.Close()
rc.mu.Unlock()
}
rc.setIsConnected(false)
rc.isConnected = false
rc.mu.Unlock()
}
// Shutdown gracefully closes the connection by sending the websocket.CloseMessage.
@@ -434,7 +433,8 @@ func (rc *RecConn) keepAlive() {
}
<-ticker.C
if time.Since(keepAliveResponse.getLastResponse()) > rc.getKeepAliveTimeout() {
timeoutOffset := time.Millisecond * 500
if time.Since(keepAliveResponse.getLastResponse()) > rc.getKeepAliveTimeout()+timeoutOffset {
rc.log(LogValues{Err: errors.New("keepalive timeout"), Msg: "Reconnect", Url: rc.url})
rc.CloseAndReconnect()
return