Example #1
0
    def __send_windows(self, buf):
        if self._write_pending:
            try:
                nBytesWritten = winutils.get_overlapped_result(self.pipe,
                                                               self._write,
                                                               False)
                self._write_pending = False
                return nBytesWritten
            except pywintypes.error as e:
                if e.winerror == winutils.winerror.ERROR_IO_INCOMPLETE:
                    # The operation is still pending, try again
                    self._read_pending = True
                    return -errno.EAGAIN
                elif e.winerror in winutils.pipe_disconnected_errors:
                    # If the pipe was disconnected, return connection reset.
                    return -errno.ECONNRESET
                else:
                    return -errno.EINVAL

        buf = winutils.get_encoded_buffer(buf)
        self._write_pending = False
        (errCode, nBytesWritten) = winutils.write_file(self.pipe,
                                                       buf,
                                                       self._write)
        if errCode:
            if errCode == winutils.winerror.ERROR_IO_PENDING:
                self._write_pending = True
                return -errno.EAGAIN
            if (not nBytesWritten and
                    errCode in winutils.pipe_disconnected_errors):
                # If the pipe was disconnected, return connection reset.
                return -errno.ECONNRESET
        return nBytesWritten
 def __send_windows(self, buf):
     if self._write_pending:
         try:
             nBytesWritten = winutils.get_overlapped_result(self.pipe,
                                                            self._write,
                                                            False)
             self._write_pending = False
         except pywintypes.error as e:
             if e.winerror == winutils.winerror.ERROR_IO_INCOMPLETE:
                 # The operation is still pending, try again
                 self._read_pending = True
                 return -errno.EAGAIN
             elif e.winerror in winutils.pipe_disconnected_errors:
                 # If the pipe was disconnected, return connection reset.
                 return -errno.ECONNRESET
             else:
                 return -errno.EINVAL
     else:
         (errCode, nBytesWritten) = winutils.write_file(self.pipe,
                                                        buf,
                                                        self._write)
         if errCode:
             if errCode == winutils.winerror.ERROR_IO_PENDING:
                 self._write_pending = True
                 return -errno.EAGAIN
             if (not nBytesWritten and
                     errCode in winutils.pipe_disconnected_errors):
                 # If the pipe was disconnected, return connection reset.
                 return -errno.ECONNRESET
     return nBytesWritten