Skip to content

Commit

Permalink
write LobRequestHeader only if there is enough space available
Browse files Browse the repository at this point in the history
  • Loading branch information
holgerkoser committed Sep 14, 2015
1 parent b671a71 commit 9531c2a
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules
coverage
config.json
hdb.js
examples/test*.js
examples/test*.js
npm-debug.log
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ After a successful SAML authentication the server returns the database `user` an

#### Kerberos
A Kerberos authentication provider can be used to authenticate users.
> This mechanism is currently not implemented. Please contact me if you require Kerberos based authentication.
> This mechanism is not implemented and I do not plan to implement a Kerberos authentication provider myself. Contributions via pull request are welcome.
### Encrypted network communication
To establish an encrypted database connection just pass whether `key`, `cert` and `ca` or a `pfx` to createClient.
Expand Down
7 changes: 6 additions & 1 deletion examples/app8.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ function execute(cb) {
}

function reconnect(cb) {
client.set('autoReconnect', true);
// reconnect on close
client.on('close', function onclose(hadError) {
if (hadError) {
this.connect();
}
});
// simulate a network error
client._connection._socket.end();
client.once('connect', function reconnected() {
Expand Down
8 changes: 5 additions & 3 deletions lib/protocol/Writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var TypeCode = common.TypeCode;
var LobOptions = common.LobOptions;
var NormalizedTypeCode = common.NormalizedTypeCode;
var bignum = util.bignum;
var WRITE_LOB_REQUEST_HEADER_LENGTH = 21;

exports = module.exports = Writer;

Expand Down Expand Up @@ -162,7 +163,7 @@ Writer.prototype.finializeParameters = function finializeParameters(
}

function next() {
if (!self._lobs.length || !bytesRemaining) {
if (!self._lobs.length || bytesRemaining <= 0) {
return cb(null);
}
// set reabable stream
Expand Down Expand Up @@ -270,13 +271,14 @@ Writer.prototype.finalizeWriteLobRequest = function finalizeWriteLobRequest(
}

function next() {
if (!self._lobs.length || !bytesRemaining) {
// no more lobs to write or not enough bytes remaining for next lob
if (!self._lobs.length || bytesRemaining <= WRITE_LOB_REQUEST_HEADER_LENGTH) {
return cb(null);
}
// set reabable stream
stream = self._lobs[0];
// set lob header
header = new Buffer(21);
header = new Buffer(WRITE_LOB_REQUEST_HEADER_LENGTH);
// set locatorId
stream._locatorId.copy(header, 0);
// update lob options in header
Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"type": "git",
"url": "git://github.com/SAP/node-hdb.git"
},
"license": "Apache 2.0",
"license": "Apache-2.0",
"keywords": [
"sap",
"hana",
Expand All @@ -29,16 +29,16 @@
},
"dependencies": {},
"devDependencies": {
"async": "^0.9.0",
"chrome-net": "^2.4.3",
"concat-stream": "^1.4.8",
"coveralls": "^2.11.1",
"debuglog": "^1.0.0",
"fstream": "^1.0.6",
"async": "^1.4.2",
"chrome-net": "^3.0.1",
"concat-stream": "^1.5.0",
"coveralls": "^2.11.4",
"debuglog": "^1.0.1",
"fstream": "^1.0.8",
"generic-pool": "^2.2.0",
"istanbul": "^0.3.13",
"mocha": "^2.2.4",
"should": "^6.0.1"
"istanbul": "^0.3.20",
"mocha": "^2.3.2",
"should": "^7.1.0"
},
"optionalDependencies": {}
}
7 changes: 7 additions & 0 deletions test/lib.Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ describe('Lib', function () {
connection.readyState.should.equal('closed');
});

it('should close an already closed Connection', function () {
var connection = createConnection();
connection._state = undefined;
connection.close();
connection.readyState.should.equal('closed');
});

it('should open and close a Connection', function (done) {
var connection = createConnection();
connection.open({}, function (err) {
Expand Down

0 comments on commit 9531c2a

Please sign in to comment.