Permalink
Browse files

bug fixes for queue, and writing to already closed connections

  • Loading branch information...
1 parent ca4aac4 commit 5040a50c6fe35fcd9f86aa1cd5d2f26ddbfbf8b4 @Jud Jud committed with Feb 4, 2011
Showing with 18 additions and 5 deletions.
  1. +18 −5 fleetdb.js
View
23 fleetdb.js
@@ -47,11 +47,21 @@ Database.prototype.open = function (uri, callback)
o.conn.on('connect', function() {
var q = o.queue.pop();
- o.conn.write(q);
+ if(q != null)
+ {
+ o.conn.write(q);
+ }
});
- o.conn.on('data', function(data) {
- var obj = JSON.parse(data);
+ o.conn.on('data', function(data) {
+
+ try {
+ var obj = JSON.parse(data);
+ } catch (SyntaxError) {
+ console.log('Invalid JSON:');
+ console.log(data);
+ return false;
+ }
var callback = o.q_stack.pop();
callback(obj[0], obj[1]);
@@ -67,7 +77,10 @@ Database.prototype.open = function (uri, callback)
} else
{
var q = o.queue.pop();
- o.conn.write(q);
+ if((o.conn != null) && (q != null))
+ {
+ o.conn.write(q);
+ }
}
});
@@ -122,4 +135,4 @@ Database.prototype.close = function()
o.conn = null;
}
}
-}
+}

0 comments on commit 5040a50

Please sign in to comment.