def _pipe_read(self, buf): read = c_ulong(0) r = ReadFile(self.pipe_handle, self.read_buffer_ptr, BUFSIZE, byref(read), byref(self.read_overlapped)) log("ReadFile(..)=%i, len=%s", r, read.value) if not r and self.pipe_handle: e = GetLastError() if e != ERROR_IO_PENDING: log("ReadFile: %s", IO_ERROR_STR.get(e, e)) r = WaitForSingleObject(self.read_event, INFINITE) log("WaitForSingleObject(..)=%s, len=%s", WAIT_STR.get(r, r), read.value) if r and self.pipe_handle: raise Exception("failed to read from named pipe handle %s" % self.pipe_handle) if self.pipe_handle: if not GetOverlappedResult(self.pipe_handle, byref(self.read_overlapped), byref(read), False): e = GetLastError() if e != ERROR_BROKEN_PIPE: raise Exception("overlapped read failed: %s" % IO_ERROR_STR.get(e, e)) if read.value == 0: data = None else: data = string_at(self.read_buffer_ptr, read.value) log("pipe_read: %i bytes", len(data or "")) #, binascii.hexlify(s)) return data
def _pipe_read(self, n): read = c_ulong(0) n_bytes = DWORD(min(n, BUFSIZE)) r = ReadFile(self.pipe_handle, self.read_buffer_ptr, n_bytes, byref(read), byref(self.read_overlapped)) log("ReadFile(%i)=%i, len=%s", n, r, read.value) if not r and self.pipe_handle: e = GetLastError() if e!=ERROR_IO_PENDING: log("ReadFile: %s", IO_ERROR_STR.get(e, e)) if e in CONNECTION_CLOSED_ERRORS: raise ConnectionClosedException(CONNECTION_CLOSED_ERRORS[e]) r = WaitForSingleObject(self.read_event, INFINITE) log("WaitForSingleObject(..)=%s, len=%s", WAIT_STR.get(r, r), read.value) if r and self.pipe_handle: raise Exception("failed to read from named pipe handle %s" % self.pipe_handle) if self.pipe_handle: if not GetOverlappedResult(self.pipe_handle, byref(self.read_overlapped), byref(read), False): e = GetLastError() if e in CONNECTION_CLOSED_ERRORS: raise ConnectionClosedException(CONNECTION_CLOSED_ERRORS[e]) raise Exception("overlapped read failed: %s" % IO_ERROR_STR.get(e, e)) if read.value==0: data = None else: data = string_at(self.read_buffer_ptr, read.value) log("pipe_read: %i bytes", len(data or "")) #, binascii.hexlify(s)) return data