Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Cleanup

  • Loading branch information...
commit f6197f7cc29d1ac76883f1fb208ca35f9552eb40 1 parent 6102ee3
@gatesvp authored
Showing with 25 additions and 20 deletions.
  1. +2 −0  constants.js
  2. +13 −8 insertHandler.js
  3. +10 −12 server.js
View
2  constants.js
@@ -16,4 +16,6 @@ constants.OPTS_NO_CURSOR_TIMEOUT = 16;
constants.OPTS_AWAIT_DATA = 32;
constants.OPTS_EXHAUST = 64;
+constants.DEFAULT_PORT = 27017;
+
exports.constants = constants;
View
21 insertHandler.js
@@ -13,8 +13,8 @@ exports.insertHandler = function(socket, header, data){
// Next is a null-terminated collection name
var fullCollectionName = "";
- for(i = 3; i++; i < data.length) {
- if(data[i] == 0) { break; }
+ for(var i = 3; i++; i < data.length) {
+ if(data[i] === 0) { break; }
fullCollectionName += String.fromCharCode(data[i]);
}
i++; // skip the null;
@@ -65,7 +65,7 @@ exports.insertHandler = function(socket, header, data){
}
-_writeData = function(collectionPath, message_data){
+var _writeData = function(collectionPath, message_data){
// Ensure that an ID is defined (or create one)
if(!message_data._id) { message_data._id = new objectid(); }
@@ -76,20 +76,25 @@ _writeData = function(collectionPath, message_data){
fs.writeFile(file_name, binary_data, 'UTF-8', function(err){
if(err) { throw err; }
else {
- return true
+ return true;
}
});
-}
+};
-mkdirP = function (p, mode, f) {
+var mkdirP = function (p, mode, f) {
var cb = f || function () {};
- if (p.charAt(0) != '/') { cb('Relative path: ' + p); return }
+ if (p.charAt(0) !== '/') {
+ cb('Relative path: ' + p);
+ return;
+ }
var ps = path.normalize(p).split('/');
path.exists(p, function (exists) {
if (exists) cb(null);
else mkdirP(ps.slice(0,-1).join('/'), mode, function (err) {
- if (err && err.errno != process.EEXIST) cb(err)
+ if (err && err.errno != process.EEXIST) {
+ cb(err);
+ }
else {
console.log("Created folder %s", p);
fs.mkdir(p, mode, cb);
View
22 server.js
@@ -17,17 +17,15 @@ Buffer.prototype.writeInt64LE = function(value, offset){
this[offset+7] = (value >> 56) & 0xff;
}
-var connection_id = 0;
-
-dataHandler = function(socket, data){
+var dataHandler = function(socket, data){
console.log("Data received: " + data.length);
var header = { messageLength:0, requestID:0, responseTo:0, opCode:0 };
header.messageLength = data.readInt32LE(0, false);
- header.requestID = data.readInt32LE(4, false);;
- header.responseTo = data.readInt32LE(8, false);;
+ header.requestID = data.readInt32LE(4, false);
+ header.responseTo = data.readInt32LE(8, false);
header.opCode = data.readInt32LE(12, false);
console.log("Header: " + JSON.stringify(header));
@@ -46,23 +44,23 @@ dataHandler = function(socket, data){
};
-closeConnection = function(connID) {
+var closeConnection = function(connID) {
var currentTime = new Date();
console.log(currentTime.getHours()+":"+currentTime.getMinutes()+":"+currentTime.getSeconds()+" : closed connection " + connID );
-}
+};
-endConnection = function(connID) {
+var endConnection = function(connID) {
var currentTime = new Date();
console.log(currentTime.getHours()+":"+currentTime.getMinutes()+":"+currentTime.getSeconds()+" : client ended connection " + connID );
-}
+};
-dataWritten = function() {
+var dataWritten = function() {
var currentTime = new Date();
//console.log(currentTime.getHours()+":"+currentTime.getMinutes()+":"+currentTime.getSeconds()+" : data written");
}
var connection_id = 0; // global connection_id
-socketHandler = function(socket) {
+var socketHandler = function(socket) {
var my_connection_id = connection_id++;
@@ -83,7 +81,7 @@ socketHandler = function(socket) {
var server = net.createServer({allowHalfOpen:true});
server.on('connection', socketHandler);
server.on('listening', function() { console.log("now listening %s:%s", server.address().address, server.address().port); } );
-server.listen(27017);
+server.listen(constants.DEFAULT_PORT);
Please sign in to comment.
Something went wrong with that request. Please try again.