Skip to content

Commit

Permalink
fix(websocket): fix redial
Browse files Browse the repository at this point in the history
Change-Id: I926011f98c6d805f509bc0a4e88ed6c5eb29459b
  • Loading branch information
andeya committed Oct 21, 2019
1 parent e295d9f commit ebe1f63
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions mixer/websocket/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (*clientPlugin) Name() string {
return "websocket"
}

func (c *clientPlugin) PostDial(sess tp.PreSession, isRedial bool) *tp.Status {
func (c *clientPlugin) PostDial(sess tp.PreSession, isRedial bool) (stat *tp.Status) {
var location, origin string
if sess.Peer().TLSConfig() == nil {
location = "ws://" + sess.RemoteAddr().String() + c.rootPath
Expand All @@ -95,13 +95,15 @@ func (c *clientPlugin) PostDial(sess tp.PreSession, isRedial bool) *tp.Status {
if err != nil {
return tp.NewStatus(tp.CodeDialFailed, "upgrade to websocket failed", err.Error())
}
var stat *tp.Status
sess.ModifySocket(func(conn net.Conn) (net.Conn, tp.ProtoFunc) {
conn, err := ws.NewClient(cfg, conn)
if err != nil {
stat = tp.NewStatus(tp.CodeDialFailed, "upgrade to websocket failed", err.Error())
return nil, nil
}
if isRedial {
return conn, sess.GetProtoFunc()
}
return conn, NewWsProtoFunc(sess.GetProtoFunc())
})
return stat
Expand Down
6 changes: 3 additions & 3 deletions mixer/websocket/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ func NewWsProtoFunc(subProto ...tp.ProtoFunc) tp.ProtoFunc {
return func(rw tp.IOWithReadBuffer) socket.Proto {
// When called, the lock of the external socket.Socket is already locked,
// so it is concurrent security.
conn, ok := rw.(socket.UnsafeSocket).RawLocked().(*ws.Conn)
connIface := rw.(socket.UnsafeSocket).RawLocked()
conn, ok := connIface.(*ws.Conn)
if !ok {
tp.Warnf("connection does not support websocket protocol")
if len(subProto) > 0 {
return subProto[0](rw)
}
return socket.DefaultProtoFunc()(rw)
return defaultProto(rw)
}
subConn := newVirtualConn()
p := &wsProto{
Expand Down

0 comments on commit ebe1f63

Please sign in to comment.