mirror of
https://github.com/mclueppers/xo-server.git
synced 2025-04-08 20:55:02 +02:00
Various fixes.
This commit is contained in:
parent
c140216fc3
commit
4ea335b974
17
src/api.js
17
src/api.js
@ -496,3 +496,20 @@ Api.fn.server = {
|
||||
throw Api.err.NOT_IMPLEMENTED;
|
||||
},
|
||||
};
|
||||
|
||||
// Extra methods not really bound to an object.
|
||||
Api.fn.xo = {
|
||||
'getStats': function () {
|
||||
// @todo
|
||||
|
||||
return {
|
||||
'hosts': 2,
|
||||
'vms': 5,
|
||||
'running_vms': 4,
|
||||
'memory': 3.5*1024*1024*1024,
|
||||
'vcpus': 15,
|
||||
'vifs': 3,
|
||||
'srs': 1,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
@ -22,7 +22,7 @@ function Collection(models)
|
||||
// Parent constructor.
|
||||
Collection.super_.call(this);
|
||||
|
||||
this.models = [];
|
||||
this.models = {};
|
||||
|
||||
this.next_id = 0;
|
||||
|
||||
@ -125,7 +125,7 @@ Collection.prototype.where = function (properties) {
|
||||
/* jshint newcap: false */
|
||||
if (_.isEmpty(properties))
|
||||
{
|
||||
return Q(this.models.slice());
|
||||
return Q(_.extend({}, this.models));
|
||||
}
|
||||
|
||||
return Q(_.where(this.models, properties));
|
||||
|
11
src/main.js
11
src/main.js
@ -109,7 +109,7 @@ require('net').createServer(function (socket) {
|
||||
});
|
||||
|
||||
var length = null; // Expected message length.
|
||||
var buffer = new Buffer();
|
||||
var buffer = new Buffer(1024); // @todo I hate hardcoded values!
|
||||
socket.on('data', function (data) {
|
||||
data.copy(buffer);
|
||||
|
||||
@ -122,7 +122,7 @@ require('net').createServer(function (socket) {
|
||||
return;
|
||||
}
|
||||
|
||||
length = +buffer.toString('ascii', 0, i);
|
||||
length = +(buffer.toString('ascii', 0, i));
|
||||
|
||||
// If the length is NaN, we cannot do anything except
|
||||
// closing the connection.
|
||||
@ -145,15 +145,18 @@ require('net').createServer(function (socket) {
|
||||
session,
|
||||
buffer.slice(0, length).toString()
|
||||
).then(function (response) {
|
||||
socket.write(response); // @todo Handle long messages.
|
||||
// @todo Handle long messages.
|
||||
socket.write(response.length +'\n'+ response);
|
||||
}).done();
|
||||
|
||||
// @todo Check it frees the memory.
|
||||
buffer = buffer.slice(length);
|
||||
|
||||
length = null;
|
||||
});
|
||||
|
||||
// @todo Ugly inter dependency.
|
||||
socket.once('close', function () {
|
||||
session.close();
|
||||
});
|
||||
}).listen(8081); // @todo Should be configurable.
|
||||
}).listen(1024); // @todo Should be configurable.
|
||||
|
@ -64,6 +64,11 @@ Model.prototype.set = function (properties, value) {
|
||||
|
||||
var model = this;
|
||||
_.each(properties, function (value, key) {
|
||||
if (undefined === value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var prev = model.get(key);
|
||||
|
||||
// New value.
|
||||
|
Loading…
x
Reference in New Issue
Block a user