实现请求连接数等限制

This commit is contained in:
刘祥超
2021-12-12 11:48:01 +08:00
parent bb5fa38613
commit e5f9316e33
20 changed files with 632 additions and 86 deletions

View File

@@ -8,13 +8,13 @@ import (
"time"
)
// ClientTLSConn TLS连接封装
type ClientTLSConn struct {
rawConn *tls.Conn
isClosed bool
BaseClientConn
}
func NewClientTLSConn(conn *tls.Conn) net.Conn {
return &ClientTLSConn{rawConn: conn}
return &ClientTLSConn{BaseClientConn{rawConn: conn}}
}
func (this *ClientTLSConn) Read(b []byte) (n int, err error) {
@@ -29,6 +29,10 @@ func (this *ClientTLSConn) Write(b []byte) (n int, err error) {
func (this *ClientTLSConn) Close() error {
this.isClosed = true
// 单个服务并发数限制
sharedClientConnLimiter.Remove(this.rawConn.RemoteAddr().String())
return this.rawConn.Close()
}
@@ -51,7 +55,3 @@ func (this *ClientTLSConn) SetReadDeadline(t time.Time) error {
func (this *ClientTLSConn) SetWriteDeadline(t time.Time) error {
return this.rawConn.SetWriteDeadline(t)
}
func (this *ClientTLSConn) IsClosed() bool {
return this.isClosed
}