xpra icon
Bug tracker and wiki

Ticket #1174: named-pipes-mess-v2.patch

File named-pipes-mess-v2.patch, 2.0 KB (added by Antoine Martin, 3 years ago)

trying to not deadlock

  • xpra/platform/win32/namedpipes/connection.py

     
    99import binascii
    1010import win32api     #@UnresolvedImport
    1111from xpra.net.bytestreams import Connection
    12 from win32pipe import DisconnectNamedPipe                                   #@UnresolvedImport
     12from win32pipe import PeekNamedPipe, DisconnectNamedPipe                                   #@UnresolvedImport
    1313from win32file import ReadFile, WriteFile, CloseHandle, FlushFileBuffers    #@UnresolvedImport
    1414from pywintypes import error                                                #@UnresolvedImport
    1515import winerror     #@UnresolvedImport
     
    3535    def read(self, n):
    3636        return self._read(self._pipe_read, n)
    3737
    38     def _pipe_read(self, buf):
     38    def _pipe_read(self, n):
    3939        data = []
    4040        hr = winerror.ERROR_MORE_DATA
    41         while hr==winerror.ERROR_MORE_DATA:
    42             hr, d = ReadFile(self.pipe_handle, 65536)
    43             data.append(d)
     41        while hr in (winerror.ERROR_MORE_DATA, winerror.ERROR_IO_PENDING) or (hr==0 and not data):
     42            hr = 0
     43            read, nAvail, result = PeekNamedPipe(self.pipe_handle, 32768)
     44            if n < nAvail:
     45                nAvail = n
     46            if n > 0:
     47                hr, d = ReadFile(self.pipe_handle, 32768)
     48                log("ReadFile returned %i bytes", len(d or ""))
     49                if d:
     50                    data.append(d)
    4451        s = b"".join(data)
    4552        log("pipe_read: %i / %s", hr, binascii.hexlify(s))
    4653        return s
     
    6168            code = e[0]
    6269            if code==winerror.ERROR_PIPE_NOT_CONNECTED:
    6370                l = log.debug
    64             l("Error: %s(%s) %i: %s", fn, self.pipe_handle, code, e)
     71            l("Error: %s(%s) %i: %s", fn, self.pipe_handle, code, e[2])
    6572        try:
    6673            DisconnectNamedPipe(self.pipe_handle)
    6774        except Exception as e: