Reconnect when connection to apple servers is half closed (CLOSE_WAIT)

When the apple servers (remote side) closed the connection on their side
(FIN) or a timeout occured (because no data was sent) the local side
continued to send messages via the socket which is then in CLOSE_WAIT.
As a result some messages get lost as only the last message is resent
when the SSL layer raises an error.

These connections could be seen in close-wait state via netstat.

This patch checks if we could read from the socket which is only
possible if the connection is not in a close-wait state. Then the
connection is reestablished.