| 944 | } |
| 945 | |
| 946 | func (cn *Conn) Close() error { |
| 947 | if cn.IsClosed() { |
| 948 | return nil |
| 949 | } |
| 950 | // Transition to CLOSED state |
| 951 | cn.stateMachine.Transition(StateClosed) |
| 952 | |
| 953 | if cn.onClose != nil { |
| 954 | // ignore error |
| 955 | _ = cn.onClose() |
| 956 | cn.onClose = nil |
| 957 | } |
| 958 | |
| 959 | // Lock-free netConn access for better performance |
| 960 | if netConn := cn.getNetConn(); netConn != nil { |
| 961 | return netConn.Close() |
| 962 | } |
| 963 | return nil |
| 964 | } |
| 965 | |
| 966 | // MaybeHasData tries to peek at the next byte in the socket without consuming it |
| 967 | // This is used to check if there are push notifications available |