修正本地发送数据的idx问题

This commit is contained in:
lwch
2021-09-28 12:04:16 +08:00
parent 6f78331781
commit c21093bbbd
4 changed files with 14 additions and 14 deletions
-1
View File
@@ -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{}{}
}
-10
View File
@@ -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)
+12 -1
View File
@@ -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 {
+2 -2
View File
@@ -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{}),
}
}