Are you trying to detect the case where a push of data would be replied to with a TCP packet with RST set? That happens asynchronously, so I'm not sure write() would return an error. Maybe the _next_ call to write(). You might be able to get a SIGPIPE or something.