1 Star 0 Fork 0

zhuchance/kubernetes

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
connection.go 1.11 KB
一键复制 编辑 原始数据 按行查看 历史
package ws
import (
"github.com/gorilla/websocket"
"io"
"log"
"time"
)
// Wrap an HTTP2 connection over WebSockets and
// use the underlying WebSocket framing for proxy
// compatibility.
type Conn struct {
*websocket.Conn
reader io.Reader
}
func NewConnection(w *websocket.Conn) *Conn {
return &Conn{Conn: w}
}
func (c Conn) Write(b []byte) (int, error) {
err := c.WriteMessage(websocket.BinaryMessage, b)
if err != nil {
return 0, err
}
return len(b), nil
}
func (c Conn) Read(b []byte) (int, error) {
if c.reader == nil {
t, r, err := c.NextReader()
if err != nil {
return 0, err
}
if t != websocket.BinaryMessage {
log.Printf("ws: ignored non-binary message in stream")
return 0, nil
}
c.reader = r
}
n, err := c.reader.Read(b)
if err != nil {
if err == io.EOF {
c.reader = nil
}
return n, err
}
return n, nil
}
func (c Conn) SetDeadline(t time.Time) error {
if err := c.Conn.SetReadDeadline(t); err != nil {
return err
}
if err := c.Conn.SetWriteDeadline(t); err != nil {
return err
}
return nil
}
func (c Conn) Close() error {
err := c.Conn.Close()
return err
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/meoom/kubernetes.git
git@gitee.com:meoom/kubernetes.git
meoom
kubernetes
kubernetes
v0.12.0

搜索帮助