diff --git a/.gitignore b/.gitignore index b8dbc72c..30fb7f3d 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,7 @@ node_modules/ .vs/ settings.json +/PushSharp.1.0.6.nupkg +/PushSharp.4.0.10.1.nupkg +/PushSharp.Core.1.0.6340.27706.nupkg +/PushSharp.Apple.1.0.6340.27706.nupkg diff --git a/PushSharp.4.0.11.nupkg b/PushSharp.4.0.11.nupkg new file mode 100644 index 00000000..3516b82c Binary files /dev/null and b/PushSharp.4.0.11.nupkg differ diff --git a/PushSharp.Apple/ApnsConnection.cs b/PushSharp.Apple/ApnsConnection.cs index 0908b166..2d27f85b 100644 --- a/PushSharp.Apple/ApnsConnection.cs +++ b/PushSharp.Apple/ApnsConnection.cs @@ -119,9 +119,13 @@ async Task SendBatch () // Let's store the batch items to send internally var toSend = new List (); - while (notifications.Count > 0 && toSend.Count < Configuration.InternalBatchSize) { - var n = notifications.Dequeue (); - toSend.Add (n); + lock (notificationBatchQueueLock) + { + while (notifications.Count > 0 && toSend.Count < Configuration.InternalBatchSize) + { + var n = notifications.Dequeue (); + toSend.Add(n); + } } @@ -154,13 +158,24 @@ async Task SendBatch () } foreach (var n in toSend) - sent.Add (new SentNotification (n)); + sent.Add(new SentNotification(n)); } } catch (Exception ex) { Log.Error ("APNS-CLIENT[{0}]: Send Batch Error: Batch ID={1}, Error={2}", id, batchId, ex); + var errorNotificationToSend = new List(); + foreach (var n in toSend) - n.CompleteFailed (new ApnsNotificationException (ApnsNotificationErrorStatusCode.ConnectionError, n.Notification, ex)); + { + if (!n.Notification.IsDeviceRegistrationIdValid()) + errorNotificationToSend.Add(n); + else + notifications.Enqueue(n); + } + + foreach (var n in errorNotificationToSend) + n.CompleteFailed(new ApnsNotificationException(ApnsNotificationErrorStatusCode.ConnectionError, n.Notification, ex)); + } Log.Info ("APNS-Client[{0}]: Sent Batch, waiting for possible response...", id);