Throw an IOError corresponding to the current socket error if
the IO action returns a result of -1, but retries in case of an
interrupted operation. Checks for operations that would block and
executes an alternative action before retrying in that case.