Allow transports to define their own ping mechanism

This commit is contained in:
Wichert Akkerman
2019-10-15 20:56:11 +02:00
committed by Mickaël Rémond
parent d0f2b492ac
commit 36e153f981
4 changed files with 25 additions and 2 deletions

View File

@@ -2,6 +2,7 @@ package xmpp
import (
"crypto/tls"
"errors"
"net"
"time"
)
@@ -59,6 +60,17 @@ func (t *XMPPTransport) StartTLS(domain string) error {
return nil
}
func (t XMPPTransport) Ping() error {
n, err := t.conn.Write([]byte("\n"))
if err != nil {
return err
}
if n != 1 {
return errors.New("Could not write ping")
}
return nil
}
func (t XMPPTransport) Read(p []byte) (n int, err error) {
return t.conn.Read(p)
}