-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
transports/websocket: Rewrite from scratch
Use github.com/sourcegraph/jsonrpc2 and github.com/gorilla/websocket. The transport package should be more robust now. The code is much less messy and it uses up-to-date packages. The transport API is also changes. You can now pass multiple WebSocket endpoint URLs and the auto-reconnect logic will use round-robin to rotate between the URLs provided.
- Loading branch information
Showing
6 changed files
with
209 additions
and
385 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package websocket | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/gorilla/websocket" | ||
jsonrpc2websocket "github.com/sourcegraph/jsonrpc2/websocket" | ||
) | ||
|
||
// ObjectStream implements jsonrpc2.ObjectStream that uses a WebSocket. | ||
// It extends jsonrpc2/websocket.ObjectStream with read/write timeouts. | ||
type ObjectStream struct { | ||
conn *websocket.Conn | ||
stream jsonrpc2websocket.ObjectStream | ||
|
||
writeTimeout time.Duration | ||
readTimeout time.Duration | ||
} | ||
|
||
func NewObjectStream(conn *websocket.Conn, writeTimeout, readTimeout time.Duration) *ObjectStream { | ||
return &ObjectStream{conn, jsonrpc2websocket.NewObjectStream(conn), writeTimeout, readTimeout} | ||
} | ||
|
||
func (stream *ObjectStream) WriteObject(v interface{}) error { | ||
stream.conn.SetWriteDeadline(time.Now().Add(stream.writeTimeout)) | ||
return stream.stream.WriteObject(v) | ||
} | ||
|
||
func (stream *ObjectStream) ReadObject(v interface{}) error { | ||
stream.conn.SetReadDeadline(time.Now().Add(stream.readTimeout)) | ||
return stream.stream.ReadObject(v) | ||
} | ||
|
||
func (stream *ObjectStream) Close() error { | ||
return stream.stream.Close() | ||
} |
Oops, something went wrong.