This commit is contained in:
风扇滑翔翼 2025-06-26 04:26:10 +08:00 committed by GitHub
commit 984a38e063
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 40 additions and 14 deletions

View file

@ -166,7 +166,7 @@ func (f *DialingWorkerFactory) Create() (*ClientWorker, error) {
type ClientStrategy struct {
MaxConcurrency uint32
MaxConnection uint32
MaxReuseTimes uint32
}
type ClientWorker struct {
@ -174,6 +174,7 @@ type ClientWorker struct {
link transport.Link
done *done.Instance
strategy ClientStrategy
timeCretaed time.Time
}
var (
@ -188,6 +189,7 @@ func NewClientWorker(stream transport.Link, s ClientStrategy) (*ClientWorker, er
link: stream,
done: done.New(),
strategy: s,
timeCretaed: time.Now(),
}
go c.fetchOutput()
@ -270,7 +272,7 @@ func fetchInput(ctx context.Context, s *Session, output buf.Writer) {
func (m *ClientWorker) IsClosing() bool {
sm := m.sessionManager
if m.strategy.MaxConnection > 0 && sm.Count() >= int(m.strategy.MaxConnection) {
if m.strategy.MaxReuseTimes > 0 && sm.Count() >= int(m.strategy.MaxReuseTimes) {
return true
}
return false
@ -298,6 +300,8 @@ func (m *ClientWorker) Dispatch(ctx context.Context, link *transport.Link) bool
if s == nil {
return false
}
errors.LogInfo(ctx, "allocated mux.cool subConnection ID: ", s.ID, "/", m.strategy.MaxReuseTimes)
errors.LogInfo(ctx, "living subConnections:", m.ActiveConnections(), "/", m.strategy.MaxConcurrency, ", this mux connection has been created for ", time.Since(m.timeCretaed).Truncate(time.Second))
s.input = link.Reader
s.output = link.Writer
go fetchInput(ctx, s, m.link.Writer)

View file

@ -58,7 +58,7 @@ func TestClientWorkerClose(t *testing.T) {
Writer: w1,
}, mux.ClientStrategy{
MaxConcurrency: 4,
MaxConnection: 4,
MaxReuseTimes: 4,
})
common.Must(err)
@ -68,7 +68,7 @@ func TestClientWorkerClose(t *testing.T) {
Writer: w2,
}, mux.ClientStrategy{
MaxConcurrency: 4,
MaxConnection: 4,
MaxReuseTimes: 4,
})
common.Must(err)