The 'ondrain' event for a socket isn't called if the entire buffer was flushed during the .write() call. Therefore the queue will stall in these cases. Instead we immediately call the .socketDrained() method to continue queue processing.
Tidied up code formatting
Reset notification ID when it gets too big
Use readUIntXXBE etc. methods instead of int2bytes and bytes2int
Improved control flow for errors
* Feature: Certificate and Key data can be passed directly when creating a new connection instead of providing a file name on disk. (See: `certData` and `keyData` options)
* Deliver whole write buffer if the socket is ready.
* Fixed some global memory leaks.
* Tidied up some code formatting glitches flagged by jslint
* Fixes#16, #17, #18, #19, #20
If we aren't then we can't find which notification made things go wrong then none of the rest of the method is relevant and we can just go back to draining the writeBuffer.
Basically I've fixed architectural failings of the first release. This should be far more stable than it has been previously with hopefully not too much increased overhead.
If you send many push notifications (10k) and 10th will have invalid token,
there is chance that 2k push notifications will be broken before broken pipe exception.
This commit adds checking for every push message and fix bug with close event listener.
Ideally this would give the user the option to specify an error handler in case the error is more sinister. If there is any demand for this open an issue or send a pull request.
Fencepost error with calculating the correct buffer length to store the token. This should fix an out-of-bounds error I got once with a token of incorrect length.
I'm not entirely sure I have the error checking right/sufficient.
The method of queueing pending messages whilst connecting has been changed to an array which the data is pushed/shifted from as it is no longer possible to add a listener to trigger the write because the socket will change as it is recreated.