From 27bcc90ec4e8854820bcf157914606226a6dc085 Mon Sep 17 00:00:00 2001 From: lwch Date: Mon, 1 Nov 2021 14:18:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8B=86=E5=88=86forward=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/client/tunnel/vnc/link.go | 80 ++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 38 deletions(-) diff --git a/code/client/tunnel/vnc/link.go b/code/client/tunnel/vnc/link.go index 5d0007f..c568a6c 100644 --- a/code/client/tunnel/vnc/link.go +++ b/code/client/tunnel/vnc/link.go @@ -76,48 +76,52 @@ func (link *Link) Fork(confDir string) error { // Forward forward data func (link *Link) Forward() { - go func() { - // TODO: exit by context - defer utils.Recover("capture") - defer link.close() - img, err := link.ps.Capture(3 * time.Second) + go link.remoteRead() + go link.localRead() +} + +func (link *Link) remoteRead() { + ch := link.remote.ChanRead(link.id) + for { + msg := <-ch + switch msg.GetXType() { + case network.Msg_vnc_ctrl: + } + } +} + +func (link *Link) localRead() { + // TODO: exit by context + defer utils.Recover("capture") + defer link.close() + img, err := link.ps.Capture(3 * time.Second) + if err != nil { + logging.Error("capture: %v", err) + return + } + link.sendAll(img) + link.img = img + size := img.Rect + sleep := time.Second / time.Duration(link.parent.cfg.Fps) + for { + time.Sleep(sleep) + img, err = link.ps.Capture(0) if err != nil { logging.Error("capture: %v", err) - return + continue + } + if img.Rect.Dx() != size.Dx() || + img.Rect.Dy() != size.Dy() || + link.resetQuality || + link.idx%100 == 0 { + link.sendAll(img) + link.resetQuality = false + } else { + link.sendDiff(img) } - link.sendAll(img) link.img = img - size := img.Rect - sleep := time.Second / time.Duration(link.parent.cfg.Fps) - for { - time.Sleep(sleep) - img, err = link.ps.Capture(0) - if err != nil { - logging.Error("capture: %v", err) - continue - } - if img.Rect.Dx() != size.Dx() || - img.Rect.Dy() != size.Dy() || - link.resetQuality || - link.idx%100 == 0 { - link.sendAll(img) - link.resetQuality = false - } else { - link.sendDiff(img) - } - link.img = img - link.idx++ - } - }() - go func() { - ch := link.remote.ChanRead(link.id) - for { - msg := <-ch - switch msg.GetXType() { - case network.Msg_vnc_ctrl: - } - } - }() + link.idx++ + } } func (link *Link) close() {