mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-03 07:56:42 -05:00
refactor server worker
This commit is contained in:
parent
16e4b5bda5
commit
682235cacc
@ -291,20 +291,25 @@ func (w *ServerWorker) remove(id uint16) {
|
|||||||
w.access.Unlock()
|
w.access.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *ServerWorker) handle(ctx context.Context, s *session) {
|
func handle(ctx context.Context, s *session, output buf.Writer) {
|
||||||
writer := NewResponseWriter(s.id, w.outboundRay.OutboundOutput())
|
writer := NewResponseWriter(s.id, output)
|
||||||
defer writer.Close()
|
defer writer.Close()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
log.Debug("Proxyman|Mux|ServerWorker: Session ", s.id, " ends by context.")
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
data, err := s.input.Read()
|
data, err := s.input.Read()
|
||||||
if err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
writer.Write(data)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -349,7 +354,7 @@ func (w *ServerWorker) run(ctx context.Context) {
|
|||||||
w.access.Lock()
|
w.access.Lock()
|
||||||
w.sessions[meta.SessionID] = s
|
w.sessions[meta.SessionID] = s
|
||||||
w.access.Unlock()
|
w.access.Unlock()
|
||||||
go w.handle(ctx, s)
|
go handle(ctx, s, w.outboundRay.OutboundOutput())
|
||||||
}
|
}
|
||||||
|
|
||||||
if meta.Option.Has(OptionData) {
|
if meta.Option.Has(OptionData) {
|
||||||
|
Loading…
Reference in New Issue
Block a user