Use cancel() to avoid Windows behaviour where a connection is reset if the socket is closed while there is a pending read operation.