diff --git a/code/client/connect.go b/code/client/connect.go index 51f1cc0..c3623a5 100644 --- a/code/client/connect.go +++ b/code/client/connect.go @@ -61,5 +61,4 @@ func shellCreate(conn *pool.Conn, msg *network.Msg) { } conn.SendShellCreatedOK(msg.GetFrom(), msg.GetFromIdx(), msg.GetLinkId()) lk.Forward() - lk.OnWork <- struct{}{} } diff --git a/code/client/shell/forward.go b/code/client/shell/forward.go index 1d37ffe..14a7f08 100644 --- a/code/client/shell/forward.go +++ b/code/client/shell/forward.go @@ -23,15 +23,6 @@ func (link *Link) remoteRead() { } link.targetIdx = msg.GetFromIdx() switch msg.GetXType() { - case network.Msg_shell_created: - logging.Info("shell created") - if msg.GetCrep().GetOk() { - link.OnWork <- struct{}{} - continue - } - logging.Error("create shell %s on tunnel %s failed, err=%s", - link.id, link.parent.Name, msg.GetCrep().GetMsg()) - return case network.Msg_shell_resize: // TODO case network.Msg_shell_data: @@ -51,7 +42,6 @@ func (link *Link) remoteRead() { func (link *Link) localRead() { defer utils.Recover("localRead") defer link.Close() - <-link.OnWork buf := make([]byte, 16*1024) for { n, err := link.stdout.Read(buf) diff --git a/code/client/shell/h_ws.go b/code/client/shell/h_ws.go index 897bbe0..501e4cf 100644 --- a/code/client/shell/h_ws.go +++ b/code/client/shell/h_ws.go @@ -47,6 +47,7 @@ func (shell *Shell) localForward(id string, local *websocket.Conn, remote *pool. shell.RLock() link := shell.links[id] shell.RUnlock() + <-link.onWork for { _, data, err := local.ReadMessage() if err != nil { @@ -62,14 +63,24 @@ func (shell *Shell) localForward(id string, local *websocket.Conn, remote *pool. func (shell *Shell) remoteForward(id string, ch <-chan *network.Msg, local *websocket.Conn) { defer utils.Recover("remoteForward") defer local.Close() + shell.RLock() + link := shell.links[id] + shell.RUnlock() for { msg := <-ch if msg == nil { return } + link.SetTargetIdx(msg.GetFromIdx()) switch msg.GetXType() { case network.Msg_shell_created: - logging.Info("shell created") + if msg.GetCrep().GetOk() { + link.onWork <- struct{}{} + continue + } + logging.Error("create shell %s on tunnel %s failed, err=%s", + link.id, link.parent.Name, msg.GetScreated().GetMsg()) + return case network.Msg_shell_data: err := local.WriteMessage(websocket.TextMessage, msg.GetSdata().GetData()) if err != nil { diff --git a/code/client/shell/link.go b/code/client/shell/link.go index 89b1196..a6af67c 100644 --- a/code/client/shell/link.go +++ b/code/client/shell/link.go @@ -14,7 +14,7 @@ type Link struct { target string // target id targetIdx uint32 // target idx remote *pool.Conn - OnWork chan struct{} + onWork chan struct{} // in remote pid int stdin io.WriteCloser @@ -31,7 +31,7 @@ func NewLink(parent *Shell, id, target string, remote *pool.Conn) *Link { id: id, target: target, remote: remote, - OnWork: make(chan struct{}), + onWork: make(chan struct{}), } }