Rather than just die, handle read and write to a closed port nicely by
calling the error callback with a descriptive error message.