the simple solution is check write() and if it returns false, listen for 'drain'