Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Update connection.js to support a "shutdown" command #134

Closed
wants to merge 3 commits into from

3 participants

@ejc3

This change adds a shutdown method to Connection that indicates to socketDrained that it should close connections once there are no more notifications to send. This allows APN to be run as part of a standalone program (e.g. a program that reads a list of notifications from a file). I've tested the change both with all successful messages, as well as when a few messages can't be sent. In both cases, the program does not shutdown until all messages that can be successfully sent are sent.

ejc3 added some commits
@ejc3 ejc3 Update connection.js to support a "shutdown" command
This change adds a shutdown method that indicates to socketDrained that it should close connections once there are no more notifications to send. The side effect is that the node process will end. I've tested the change both with all successful messages, as well as when a few messages can't be sent. In both cases, the program does not shutdown until all messages that can be successfully sent our sent.
212697a
@ejc3 ejc3 cleaned up extra param 5774706
@ejc3 ejc3 Update connection.js
fix spelling mistake
4c7c3ca
@rbadillo

When are you merging this change ? Let us know please

@blaiprat

+1 to this modification

@argon argon closed this pull request from a commit
@argon Improved connection shutdown behaviour.
Closes #134
38c0800
@argon argon closed this in 38c0800
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 30, 2013
  1. @ejc3

    Update connection.js to support a "shutdown" command

    ejc3 authored
    This change adds a shutdown method that indicates to socketDrained that it should close connections once there are no more notifications to send. The side effect is that the node process will end. I've tested the change both with all successful messages, as well as when a few messages can't be sent. In both cases, the program does not shutdown until all messages that can be successfully sent our sent.
  2. @ejc3

    cleaned up extra param

    ejc3 authored
  3. @ejc3

    Update connection.js

    ejc3 authored
    fix spelling mistake
This page is out of date. Refresh to see the latest.
Showing with 17 additions and 1 deletion.
  1. +17 −1 lib/connection.js
View
18 lib/connection.js
@@ -84,6 +84,9 @@ function Connection (options) {
this.socketId = 0;
+ // when true, we end all sockets after the pending notifications reach 0
+ this.shutdownPending = false;
+
events.EventEmitter.call(this);
}
@@ -99,7 +102,7 @@ Connection.prototype.checkInitialized = function () {
};
/**
- * You should never need to call this method, initialisation and connection is handled by {@link Connection#sendNotification}
+ * You should never need to call this method, initialization and connection is handled by {@link Connection#sendNotification}
* @private
*/
Connection.prototype.initialize = function () {
@@ -362,6 +365,12 @@ Connection.prototype.socketDrained = function(socket, serviceBuffer) {
}
this.runningOnNextTick = true;
}
+ if (this.notificationBuffer.length === 0 && this.shutdownPending) {
+ debug("closing connections");
+ for (var i = this.sockets.length - 1; i >= 0; i--) {
+ this.sockets[i].end();
+ }
+ }
};
/**
@@ -704,4 +713,11 @@ Connection.prototype.sendNotification = function (notification) {
return this.pushNotification(notification, notification.device);
};
+/**
+ * End connections with APNS once we've finished sending all notifications
+ */
+Connection.prototype.shutdown = function () {
+ this.shutdownPending = true;
+};
+
module.exports = Connection;
Something went wrong with that request. Please try again.