Add brutal infra

This commit is contained in:
Fangliding
2025-12-11 12:13:14 +08:00
parent 6a909b2507
commit 65da3d9c9d
5 changed files with 72 additions and 6 deletions
+2 -2
View File
@@ -170,7 +170,7 @@ func (f *DialingWorkerFactory) Create() (*ClientWorker, error) {
type ClientStrategy struct {
MaxConcurrency uint32
MaxConnection uint32
MaxReuseTimes uint32
}
type ClientWorker struct {
@@ -288,7 +288,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
+2 -2
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)
+3 -2
View File
@@ -56,11 +56,12 @@ func (m *SessionManager) Allocate(Strategy *ClientStrategy) *Session {
defer m.Unlock()
MaxConcurrency := int(Strategy.MaxConcurrency)
MaxConnection := uint16(Strategy.MaxConnection)
MaxReuseTimes := uint16(Strategy.MaxReuseTimes)
if m.closed || (MaxConcurrency > 0 && len(m.sessions) >= MaxConcurrency) || (MaxConnection > 0 && m.count >= MaxConnection) {
if m.closed || (MaxConcurrency > 0 && len(m.sessions) >= MaxConcurrency) || (MaxReuseTimes > 0 && m.count >= MaxReuseTimes) {
return nil
}
errors.LogInfo(context.Background(), "Allocated mux.cool session id ", m.count, "/", MaxReuseTimes)
m.count++
s := &Session{