This repository has been archived by the owner on Aug 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
107 additions
and
58 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
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,32 @@ | ||
package core | ||
|
||
import ( | ||
"github.com/gorilla/websocket" | ||
) | ||
|
||
type WebSocket struct { | ||
conn *websocket.Conn | ||
buf []byte | ||
} | ||
|
||
func (ws *WebSocket) Read(p []byte) (n int, err error) { | ||
if len(ws.buf) == 0 { | ||
_, ws.buf, err = ws.conn.ReadMessage() | ||
if err != nil { | ||
return | ||
} | ||
} | ||
|
||
n = copy(p, ws.buf) | ||
ws.buf = ws.buf[n:] | ||
return | ||
} | ||
|
||
func (ws *WebSocket) Write(p []byte) (n int, err error) { | ||
err = ws.conn.WriteMessage(websocket.BinaryMessage, p) | ||
if err != nil { | ||
return | ||
} | ||
|
||
return len(p), nil | ||
} |
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