0

Recently Apple modified their Technical Note TN2265 - Troubleshooting Push Notifications. They added a section about throughput and error checking.

This is taken from that section :

Here's how to check for errors when using the enhanced binary interface. Keep writing until a write fails. If the stream is ready for writing again, resend the notification and keep going. If the stream isn't ready for writing, see if the stream is available for reading.

If it is, read everything available from the stream. If you get zero bytes back, the connection was closed because of an error such as an invalid command byte or other parsing error. If you get six bytes back, that's an error response that you can check for the response code and the ID of the notification that caused the error. You'll need to send every notification following that one again.

Once everything has been sent, do one last check for an error response.

It can take a while for the dropped connection to make its way from APNs back to your server just because of normal latency. It's possible to send over 500 notifications before a write fails because of the connection being dropped. Around 1,700 notifications writes can fail just because the pipe is full, so just retry in that case once the stream is ready for writing again.

My APN provider server is written in Java using blocking sockets (SSLSocket).

Is it possible to do what they suggest in the bold text using SSLSocket? After a write fails, can I write again to the socket? Doesn't the socket close in this case? How do I know if the stream is ready for writing again? How do I know if it is available for reading?

I want to avoid using NIO, because that would require using SSLEngine, which seems painful to implement.

4

1 回答 1

0

查看 Unix/Linux/OS X write(2) 函数的手册页。如果由于操作系统的完整输出缓冲区而导致写入阻塞,您将返回 EAGAIN 或 EWOULDBLOCK 错误代码。我的猜测是,上面的“写入失败”可能是指除了“真实”错误之外的这种情况。如果您再试一次(可能只是稍晚一点,甚至立即),如果缓冲区先前已满,则写入很有可能会成功。如果 TCP 连接本身已经消失,那么除了建立新连接之外,您当然无能为力。

于 2013-04-05T07:45:50.707 回答