diff --git a/lib/commands/index.js b/lib/commands/index.js index 74a32ae8fd..9c96ec126b 100644 --- a/lib/commands/index.js +++ b/lib/commands/index.js @@ -11,6 +11,7 @@ const RegisterSlave = require('./register_slave.js'); const BinlogDump = require('./binlog_dump.js'); const ChangeUser = require('./change_user.js'); const Quit = require('./quit.js'); +const ResetConnection = require('./reset_connection.js'); module.exports = { ClientHandshake, @@ -23,5 +24,6 @@ module.exports = { RegisterSlave, BinlogDump, ChangeUser, - Quit + Quit, + ResetConnection }; diff --git a/lib/commands/reset_connection.js b/lib/commands/reset_connection.js new file mode 100644 index 0000000000..8b9ba3eae6 --- /dev/null +++ b/lib/commands/reset_connection.js @@ -0,0 +1,26 @@ +'use strict'; + +const Command = require('./command'); +const Packets = require('../packets/index.js'); + +class ResetConnection extends Command { + constructor(callback) { + super(); + this.onResult = callback; + } + + start(packet, connection) { + const req = new Packets.ResetConnection(); + connection.writePacket(req.toPacket()); + return ResetConnection.prototype.resetConnectionResponse; + } + + resetConnectionResponse() { + if (this.onResult) { + process.nextTick(this.onResult.bind(this)); + } + return null; + } +} + +module.exports = ResetConnection; diff --git a/lib/connection.js b/lib/connection.js index e2720be078..e023ea05a4 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -717,6 +717,10 @@ class Connection extends EventEmitter { return this.addCommand(new Commands.Ping(cb)); } + reset(cb) { + return this.addCommand(new Commands.ResetConnection(cb)); + } + _registerSlave(opts, cb) { return this.addCommand(new Commands.RegisterSlave(opts, cb)); } diff --git a/lib/constants/commands.js b/lib/constants/commands.js index c0ed47d069..986e4dfc58 100644 --- a/lib/constants/commands.js +++ b/lib/constants/commands.js @@ -32,5 +32,6 @@ module.exports = { STMT_FETCH: 0x1c, DAEMON: 0x1d, // deprecated BINLOG_DUMP_GTID: 0x1e, + RESET_CONNECTION: 0x1f, // introduced in 5.7.3 UNKNOWN: 0xff // bad! }; diff --git a/lib/packets/index.js b/lib/packets/index.js index bf66e1a67b..b71884e0ea 100644 --- a/lib/packets/index.js +++ b/lib/packets/index.js @@ -30,6 +30,7 @@ const RegisterSlave = require('./register_slave'); const ResultSetHeader = require('./resultset_header'); const SSLRequest = require('./ssl_request'); const TextRow = require('./text_row'); +const ResetConnection = require('./reset_connection'); const ctorMap = { AuthNextFactor, @@ -50,7 +51,8 @@ const ctorMap = { RegisterSlave, ResultSetHeader, SSLRequest, - TextRow + TextRow, + ResetConnection }; Object.entries(ctorMap).forEach(([name, ctor]) => { module.exports[name] = ctor; diff --git a/lib/packets/reset_connection.js b/lib/packets/reset_connection.js new file mode 100644 index 0000000000..d8eafa2b69 --- /dev/null +++ b/lib/packets/reset_connection.js @@ -0,0 +1,18 @@ +'use strict'; + +const Packet = require('../packets/packet'); +const CommandCodes = require('../constants/commands'); + +class ResetConnection { + constructor() { + } + + toPacket() { + const packet = new Packet(0, Buffer.allocUnsafe(5), 0, 5); + packet.offset = 4; + packet.writeInt8(CommandCodes.RESET_CONNECTION); + return packet; + } +} + +module.exports = ResetConnection; diff --git a/promise.js b/promise.js index fc74cc0c3a..257cd447dc 100644 --- a/promise.js +++ b/promise.js @@ -166,6 +166,15 @@ class PromiseConnection extends EventEmitter { }); } + reset() { + const c = this.connection; + const localErr = new Error(); + return new this.Promise((resolve, reject) => { + const done = makeDoneCb(resolve, reject, localErr); + c.reset(done); + }); + } + connect() { const c = this.connection; const localErr = new Error();