1
0
Fork 0

Allow to close the connection

This commit is contained in:
Gregory Eremin 2018-11-11 20:32:59 +01:00
parent 9e62446755
commit ca74b866b6
2 changed files with 13 additions and 1 deletions

View File

@ -33,7 +33,9 @@ func New(dsn string, sc slave.Config) (*Reader, error) {
return nil, errors.Annotate(err, "establish slave connection") return nil, errors.Annotate(err, "establish slave connection")
} }
r := &Reader{conn: conn} r := &Reader{
conn: conn,
}
r.initTableMap() r.initTableMap()
if err := conn.DisableChecksum(); err != nil { if err := conn.DisableChecksum(); err != nil {
@ -129,6 +131,11 @@ func (r *Reader) ReadEvent() (*Event, error) {
return &evt, err return &evt, err
} }
// Close underlying database connection.
func (r *Reader) Close() error {
return r.conn.Close()
}
func (r *Reader) initTableMap() { func (r *Reader) initTableMap() {
r.tableMap = make(map[uint64]binlog.TableDescription) r.tableMap = make(map[uint64]binlog.TableDescription)
} }

View File

@ -155,6 +155,11 @@ func (c *Conn) SetVar(name, val string) error {
return c.conn.Exec(fmt.Sprintf("SET %s=%q", name, val)) return c.conn.Exec(fmt.Sprintf("SET %s=%q", name, val))
} }
// Close the connection.
func (c *Conn) Close() error {
return c.conn.Close()
}
func (c *Conn) runCmd(data []byte) error { func (c *Conn) runCmd(data []byte) error {
err := c.conn.WritePacket(data) err := c.conn.WritePacket(data)
if err != nil { if err != nil {