mirror of
https://github.com/MetaCubeX/Clash.Meta.git
synced 2025-04-11 04:50:56 +00:00
Cleanup code
This commit is contained in:
parent
e76c1b65ca
commit
2e26bd32eb
2 changed files with 6 additions and 9 deletions
|
@ -83,11 +83,7 @@ func (c *Client) CreateStream(ctx context.Context) (net.Conn, error) {
|
|||
}
|
||||
|
||||
stream.dieHook = func() {
|
||||
if session.IsClosed() {
|
||||
if session.dieHook != nil {
|
||||
session.dieHook()
|
||||
}
|
||||
} else {
|
||||
if !session.IsClosed() {
|
||||
select {
|
||||
case <-c.die.Done():
|
||||
// Now client has been closed
|
||||
|
@ -154,10 +150,10 @@ func (c *Client) Close() error {
|
|||
|
||||
c.sessionsLock.Lock()
|
||||
sessionToClose := make([]*Session, 0, len(c.sessions))
|
||||
for seq, session := range c.sessions {
|
||||
for _, session := range c.sessions {
|
||||
sessionToClose = append(sessionToClose, session)
|
||||
delete(c.sessions, seq)
|
||||
}
|
||||
c.sessions = make(map[uint64]*Session)
|
||||
c.sessionsLock.Unlock()
|
||||
|
||||
for _, session := range sessionToClose {
|
||||
|
|
|
@ -108,10 +108,11 @@ func (s *Session) Close() error {
|
|||
if once {
|
||||
if s.dieHook != nil {
|
||||
s.dieHook()
|
||||
s.dieHook = nil
|
||||
}
|
||||
s.streamLock.Lock()
|
||||
for k := range s.streams {
|
||||
s.streams[k].Close()
|
||||
for _, stream := range s.streams {
|
||||
stream.Close()
|
||||
}
|
||||
s.streams = make(map[uint32]*Stream)
|
||||
s.streamLock.Unlock()
|
||||
|
|
Loading…
Add table
Reference in a new issue