From 55ecd92064136590b6f199811be0235b30bd0c98 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Tue, 4 Apr 2017 00:17:38 +0200 Subject: [PATCH] simplify mux code --- app/proxyman/mux/mux.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/app/proxyman/mux/mux.go b/app/proxyman/mux/mux.go index 673ae110..2f458d07 100644 --- a/app/proxyman/mux/mux.go +++ b/app/proxyman/mux/mux.go @@ -35,26 +35,26 @@ type session struct { downlinkClosed bool } -func (s *session) checkAndRemove() { - s.Lock() - if s.uplinkClosed && s.downlinkClosed { - s.parent.remove(s.id) - } - s.Unlock() -} - func (s *session) closeUplink() { + var allDone bool s.Lock() s.uplinkClosed = true + allDone = s.uplinkClosed && s.downlinkClosed s.Unlock() - s.checkAndRemove() + if allDone { + s.parent.remove(s.id) + } } func (s *session) closeDownlink() { + var allDone bool s.Lock() s.downlinkClosed = true + allDone = s.uplinkClosed && s.downlinkClosed s.Unlock() - s.checkAndRemove() + if allDone { + s.parent.remove(s.id) + } } type ClientManager struct { @@ -177,7 +177,7 @@ func fetchInput(ctx context.Context, s *session, output buf.Writer) { return } } - _, timer := signal.CancelAfterInactivity(ctx, time.Minute*5) + _, timer := signal.CancelAfterInactivity(ctx, time.Minute*30) if err := buf.PipeUntilEOF(timer, s.input, writer); err != nil { log.Info("Proxyman|Mux|Client: Failed to fetch all input: ", err) }