mysql2
Version:
fast mysql driver. Implements core protocol, prepared statements, ssl and compression in native JS
34 lines (27 loc) • 930 B
JavaScript
var net = require('net');
var util = require('util');
var EventEmitter = require('events').EventEmitter;
var Connection = require('./connection');
var ConnectionConfig = require('./connection_config');
// TODO: inherit Server from net.Server
function Server ()
{
EventEmitter.call(this);
this.connections = [];
this._server = net.createServer(this._handleConnection.bind(this));
}
util.inherits(Server, EventEmitter);
Server.prototype._handleConnection = function (socket) {
var connectionConfig = new ConnectionConfig({stream: socket, isServer: true});
var connection = new Connection({config: connectionConfig});
this.emit('connection', connection);
};
Server.prototype.listen = function (port, host, backlog, callback) {
this._port = port;
this._server.listen.apply(this._server, arguments);
return this;
};
Server.prototype.close = function (cb) {
this._server.close(cb);
};
module.exports = Server;