From 682235cacc31daf8df44bdd63524b6e3b490da99 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Mon, 3 Apr 2017 17:28:15 +0200 Subject: [PATCH] refactor server worker --- app/proxyman/mux/mux.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/proxyman/mux/mux.go b/app/proxyman/mux/mux.go index c28571e0..3b390b71 100644 --- a/app/proxyman/mux/mux.go +++ b/app/proxyman/mux/mux.go @@ -291,20 +291,25 @@ func (w *ServerWorker) remove(id uint16) { w.access.Unlock() } -func (w *ServerWorker) handle(ctx context.Context, s *session) { - writer := NewResponseWriter(s.id, w.outboundRay.OutboundOutput()) +func handle(ctx context.Context, s *session, output buf.Writer) { + writer := NewResponseWriter(s.id, output) defer writer.Close() for { select { case <-ctx.Done(): + log.Debug("Proxyman|Mux|ServerWorker: Session ", s.id, " ends by context.") return default: data, err := s.input.Read() if err != nil { + log.Info("Proxyman|Mux|ServerWorker: Session ", s.id, " ends: ", err) + return + } + if err := writer.Write(data); err != nil { + log.Info("Proxyman|Mux|ServerWorker: Session ", s.id, " ends: ", err) return } - writer.Write(data) } } } @@ -349,7 +354,7 @@ func (w *ServerWorker) run(ctx context.Context) { w.access.Lock() w.sessions[meta.SessionID] = s w.access.Unlock() - go w.handle(ctx, s) + go handle(ctx, s, w.outboundRay.OutboundOutput()) } if meta.Option.Has(OptionData) {