2026-04-15 15:24:36 +08:00
|
|
|
package notify
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"errors"
|
|
|
|
|
"net"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func (c *ClientConn) startClientConnSession(tuConn net.Conn, stopCtx context.Context, stopFn context.CancelFunc) (context.Context, context.CancelFunc) {
|
|
|
|
|
if c == nil {
|
|
|
|
|
return stopCtx, stopFn
|
|
|
|
|
}
|
|
|
|
|
return c.LogicalConn().startSession(tuConn, stopCtx, stopFn)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *ClientConn) startClientConnSessionTransport(tuConn net.Conn, stopCtx context.Context, stopFn context.CancelFunc) (context.Context, context.CancelFunc) {
|
|
|
|
|
if c == nil {
|
|
|
|
|
return stopCtx, stopFn
|
|
|
|
|
}
|
|
|
|
|
return c.LogicalConn().startSessionTransport(tuConn, stopCtx, stopFn)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *ClientConn) attachClientConnSessionTransport(tuConn net.Conn) error {
|
|
|
|
|
if c == nil {
|
|
|
|
|
return errors.New("client conn is nil")
|
|
|
|
|
}
|
|
|
|
|
return c.LogicalConn().attachSessionTransport(tuConn)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *ClientConn) detachClientConnTransportForTransfer() (net.Conn, error) {
|
|
|
|
|
if c == nil {
|
|
|
|
|
return nil, errors.New("client conn is nil")
|
|
|
|
|
}
|
|
|
|
|
return c.LogicalConn().detachTransportForTransfer()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *ClientConn) stopServerOwnedSession(reason string, err error) {
|
|
|
|
|
c.stopServerOwnedSessionWith(nil, reason, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *LogicalConn) stopServerOwnedSession(reason string, err error) {
|
|
|
|
|
c.stopServerOwnedSessionWith(nil, reason, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *ClientConn) stopServerOwnedSessionWith(removeFn func(*ClientConn), reason string, err error) {
|
|
|
|
|
if c == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
c.markSessionStopped(reason, err)
|
|
|
|
|
c.detachServerOwnedSessionWith(removeFn)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *LogicalConn) stopServerOwnedSessionWith(removeFn func(*LogicalConn), reason string, err error) {
|
|
|
|
|
client := c.compatClientConn()
|
|
|
|
|
if client == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
client.markSessionStopped(reason, err)
|
|
|
|
|
c.detachServerOwnedSessionWith(removeFn)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *ClientConn) detachServerOwnedSession() {
|
|
|
|
|
c.detachServerOwnedSessionWith(nil)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *LogicalConn) detachServerOwnedSession() {
|
|
|
|
|
c.detachServerOwnedSessionWith(nil)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *ClientConn) detachServerOwnedSessionWith(removeFn func(*ClientConn)) {
|
|
|
|
|
if c == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
c.detachServerOwnedTransport()
|
|
|
|
|
if removeFn != nil {
|
|
|
|
|
removeFn(c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if c.server != nil {
|
|
|
|
|
c.server.removeClient(c)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *LogicalConn) detachServerOwnedSessionWith(removeFn func(*LogicalConn)) {
|
|
|
|
|
client := c.compatClientConn()
|
|
|
|
|
if client == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
c.detachServerOwnedTransport()
|
|
|
|
|
if removeFn != nil {
|
|
|
|
|
removeFn(c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if client.server != nil {
|
|
|
|
|
client.server.removeLogical(c)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *ClientConn) detachServerOwnedTransport() {
|
|
|
|
|
if c == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
c.LogicalConn().detachServerOwnedTransport()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *LogicalConn) detachServerOwnedTransport() {
|
|
|
|
|
if c == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2026-08-14 10:16:37 +08:00
|
|
|
conn := c.transportSnapshot()
|
|
|
|
|
// Revoke read-loop ownership before closing the socket. Otherwise the close
|
|
|
|
|
// error can race with detach and incorrectly stop the logical session.
|
2026-04-15 15:24:36 +08:00
|
|
|
c.clearSessionRuntimeTransport()
|
2026-08-14 10:16:37 +08:00
|
|
|
if conn != nil {
|
|
|
|
|
_ = conn.Close()
|
|
|
|
|
}
|
2026-04-15 15:24:36 +08:00
|
|
|
}
|