mirror of
https://github.com/FluuxIO/go-xmpp.git
synced 2024-11-23 19:12:00 -08:00
Do not try to create a stream logger before we have a net.Conn
This commit is contained in:
parent
38bdcaec36
commit
a6709a1f71
@ -19,6 +19,7 @@ type XMPPTransport struct {
|
|||||||
decoder *xml.Decoder
|
decoder *xml.Decoder
|
||||||
conn net.Conn
|
conn net.Conn
|
||||||
readWriter io.ReadWriter
|
readWriter io.ReadWriter
|
||||||
|
logFile io.Writer
|
||||||
isSecure bool
|
isSecure bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,20 +33,21 @@ func (t *XMPPTransport) Connect() (string, error) {
|
|||||||
return "", NewConnError(err, true)
|
return "", NewConnError(err, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = fmt.Fprintf(t.conn, xmppStreamOpen, t.Config.Domain, stanza.NSClient, stanza.NSStream); err != nil {
|
t.readWriter = newStreamLogger(t.conn, t.logFile)
|
||||||
|
|
||||||
|
if _, err = fmt.Fprintf(t.readWriter, xmppStreamOpen, t.Config.Domain, stanza.NSClient, stanza.NSStream); err != nil {
|
||||||
t.conn.Close()
|
t.conn.Close()
|
||||||
return "", NewConnError(err, true)
|
return "", NewConnError(err, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
t.decoder = xml.NewDecoder(t.readWriter)
|
t.decoder = xml.NewDecoder(t.readWriter)
|
||||||
t.decoder.CharsetReader = t.Config.CharsetReader
|
t.decoder.CharsetReader = t.Config.CharsetReader
|
||||||
sessionId, err := stanza.InitStream(t.decoder)
|
sessionID, err := stanza.InitStream(t.decoder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.conn.Close()
|
t.conn.Close()
|
||||||
return "", NewConnError(err, false)
|
return "", NewConnError(err, false)
|
||||||
}
|
}
|
||||||
t.readWriter = t.conn
|
return sessionID, nil
|
||||||
return sessionId, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t XMPPTransport) DoesStartTLS() bool {
|
func (t XMPPTransport) DoesStartTLS() bool {
|
||||||
@ -111,5 +113,5 @@ func (t XMPPTransport) Close() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *XMPPTransport) LogTraffic(logFile io.Writer) {
|
func (t *XMPPTransport) LogTraffic(logFile io.Writer) {
|
||||||
t.readWriter = &streamLogger{t.conn, logFile}
|
t.logFile = logFile
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user