Fix write failure handling in DTLS1.2