mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-09-23 01:27:04 +00:00
WebSocket client: Avoid panic before real dialing in delayDialConn (#6544)
Fixes https://github.com/teddysun/xray-plugin-android/issues/11
This commit is contained in:
@@ -175,6 +175,25 @@ type delayDialConn struct {
|
|||||||
streamSettings *internet.MemoryStreamConfig
|
streamSettings *internet.MemoryStreamConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LocalAddr returns nil until the deferred WebSocket dial has completed.
|
||||||
|
// Without this method, Go promotes LocalAddr from the embedded net.Conn; the
|
||||||
|
// embedded interface is nil before the first Write, so the promoted call panics.
|
||||||
|
func (d *delayDialConn) LocalAddr() net.Addr {
|
||||||
|
if d.Conn == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return d.Conn.LocalAddr()
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoteAddr returns nil until the deferred WebSocket dial has completed.
|
||||||
|
// See LocalAddr for why an explicit method is required here.
|
||||||
|
func (d *delayDialConn) RemoteAddr() net.Addr {
|
||||||
|
if d.Conn == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return d.Conn.RemoteAddr()
|
||||||
|
}
|
||||||
|
|
||||||
func (d *delayDialConn) Write(b []byte) (int, error) {
|
func (d *delayDialConn) Write(b []byte) (int, error) {
|
||||||
if d.closed {
|
if d.closed {
|
||||||
return 0, io.ErrClosedPipe
|
return 0, io.ErrClosedPipe
|
||||||
|
|||||||
Reference in New Issue
Block a user