private static async Task <List <AppleFeedback> > _feedbackReadResponse(Internal.APNSConnection connection) { var rtn = new List <AppleFeedback>(); byte[] msg; while ((msg = await connection.Receive(6, true)) != null) { var timestamp = (msg[0] << 24) | (msg[1] << 16) | (msg[2] << 8) | (msg[3]); var deviceToken = await connection.Receive((msg[4] << 8) | (msg[5]), false); rtn.Add(new AppleFeedback(timestamp, deviceToken)); } return(rtn); }
private async Task _receiveResponceAsync() { byte[] msg = null; List <Notification> notifications; try { msg = await _connection.Receive(6, true); lock (_lockObject) { notifications = _notifications; _notifications = null; } _close(); } catch (Exception err) { bool connected; lock (_lockObject) { notifications = _notifications; _notifications = null; connected = _connection != null; _close(); } if (connected) { Service.Error(new PushNotificationServiceException("Receive response from APNS failed.", err)); } } if (msg != null && msg[0] == 0x08) { var ni = (msg[2] << 24) | (msg[3] << 16) | (msg[4] << 8) | (msg[5]); if (ni >= 0 && ni == _notificationIdentifier - 1 && notifications[ni] == null) { notifications = null; } else { if (ni >= 0 && ni < _notificationIdentifier) { var n = notifications[ni]; if (n != null) { Service.Error((msg[1] == 0x08) ? new PushNotificationInvalidDeviceException(n) : new PushNotificationException(n, "Submit notification to '" + n.DeviceAddress + "' failed error #" + msg[1] + ".")); } } for (int i = 0; i <= ni && i < _notificationIdentifier; ++i) { notifications[i] = null; } } Service.ConnectionClosed(this, notifications); } else { Service.NotificationDropped(notifications, new Exception("Connection dropped by APSN.")); Service.ConnectionClosed(this); } }