mirror of
https://github.com/mclueppers/xo-server.git
synced 2025-07-23 22:15:47 +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;
|
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.
|
// Parent constructor.
|
||||||
Collection.super_.call(this);
|
Collection.super_.call(this);
|
||||||
|
|
||||||
this.models = [];
|
this.models = {};
|
||||||
|
|
||||||
this.next_id = 0;
|
this.next_id = 0;
|
||||||
|
|
||||||
@ -125,7 +125,7 @@ Collection.prototype.where = function (properties) {
|
|||||||
/* jshint newcap: false */
|
/* jshint newcap: false */
|
||||||
if (_.isEmpty(properties))
|
if (_.isEmpty(properties))
|
||||||
{
|
{
|
||||||
return Q(this.models.slice());
|
return Q(_.extend({}, this.models));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Q(_.where(this.models, properties));
|
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 length = null; // Expected message length.
|
||||||
var buffer = new Buffer();
|
var buffer = new Buffer(1024); // @todo I hate hardcoded values!
|
||||||
socket.on('data', function (data) {
|
socket.on('data', function (data) {
|
||||||
data.copy(buffer);
|
data.copy(buffer);
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ require('net').createServer(function (socket) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
length = +buffer.toString('ascii', 0, i);
|
length = +(buffer.toString('ascii', 0, i));
|
||||||
|
|
||||||
// If the length is NaN, we cannot do anything except
|
// If the length is NaN, we cannot do anything except
|
||||||
// closing the connection.
|
// closing the connection.
|
||||||
@ -145,15 +145,18 @@ require('net').createServer(function (socket) {
|
|||||||
session,
|
session,
|
||||||
buffer.slice(0, length).toString()
|
buffer.slice(0, length).toString()
|
||||||
).then(function (response) {
|
).then(function (response) {
|
||||||
socket.write(response); // @todo Handle long messages.
|
// @todo Handle long messages.
|
||||||
|
socket.write(response.length +'\n'+ response);
|
||||||
}).done();
|
}).done();
|
||||||
|
|
||||||
// @todo Check it frees the memory.
|
// @todo Check it frees the memory.
|
||||||
buffer = buffer.slice(length);
|
buffer = buffer.slice(length);
|
||||||
|
|
||||||
|
length = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
// @todo Ugly inter dependency.
|
// @todo Ugly inter dependency.
|
||||||
socket.once('close', function () {
|
socket.once('close', function () {
|
||||||
session.close();
|
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;
|
var model = this;
|
||||||
_.each(properties, function (value, key) {
|
_.each(properties, function (value, key) {
|
||||||
|
if (undefined === value)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var prev = model.get(key);
|
var prev = model.get(key);
|
||||||
|
|
||||||
// New value.
|
// New value.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user