Fix handling of errors when receiving datagrams