def do_run(self): pipe_handle = None while not self.exit_loop: if not pipe_handle: try: pipe_handle = self.CreatePipeHandle() except Exception as e: log("CreatePipeHandle()", exc_info=True) log.error("Error: failed to create named pipe") log.error(" at path '%s'", self.pipe_name) log.error(" %s", e) return log("CreatePipeHandle()=%#x", pipe_handle) if c_long(pipe_handle).value==INVALID_HANDLE_VALUE: log.error("Error: invalid handle for named pipe '%s'", self.pipe_name) e = GetLastError() log.error(" '%s' (%i)", FormatMessageSystem(e).rstrip("\n\r."), e) return event = CreateEventA(None, True, False, None) overlapped = OVERLAPPED() overlapped.hEvent = event overlapped.Internal = None overlapped.InternalHigh = None overlapped.union.Pointer = None r = ConnectNamedPipe(pipe_handle, overlapped) log("ConnectNamedPipe()=%s", r) if self.exit_loop: break if r==0: e = GetLastError() log("GetLastError()=%s (%i)", FormatMessageSystem(e).rstrip("\n\r"), e) if e==ERROR_PIPE_CONNECTED: pass elif e==ERROR_IO_PENDING: while not self.exit_loop: r = WaitForSingleObject(event, INFINITE) log("WaitForSingleObject(..)=%s", WAIT_STR.get(r, r)) if r==WAIT_TIMEOUT: continue if r==0: break log.error("Error: cannot connect to named pipe '%s'", self.pipe_name) log.error(" %s", WAIT_STR.get(r, r)) CloseHandle(pipe_handle) pipe_handle = None break else: log.error("Error: cannot connect to named pipe '%s'", self.pipe_name) log.error(" error %s", e) CloseHandle(pipe_handle) pipe_handle = None if self.exit_loop: break #from now on, the pipe_handle will be managed elsewhere: if pipe_handle: self.new_connection_cb("named-pipe", self, pipe_handle) pipe_handle = None if pipe_handle: self.close_handle(pipe_handle)
def do_run(self): while not self.exit_loop: pipe_handle = None try: pipe_handle = self.CreatePipeHandle() except Exception as e: log("CreatePipeHandle()", exc_info=True) log.error("Error: failed to create named pipe") log.error(" at path '%s'", self.pipe_name) log.error(" %s", e) return log("CreatePipeHandle()=%s", pipe_handle) if pipe_handle == INVALID_HANDLE_VALUE: log.error("Error: invalid handle for named pipe '%s'", self.pipe_name) return event = CreateEventA(None, True, False, None) overlapped = OVERLAPPED() overlapped.hEvent = event overlapped.Internal = None overlapped.InternalHigh = None overlapped.union.Pointer = None r = ConnectNamedPipe(pipe_handle, overlapped) log("ConnectNamedPipe()=%s", r) if not r and not self.exit_loop: r = WaitForSingleObject(event, INFINITE) log("WaitForSingleObject(..)=%s", WAIT_STR.get(r, r)) if r: log("do_run() error on WaitForSingleObject", exc_info=True) log.error("Error: cannot connect to named pipe '%s'", self.pipe_name) CloseHandle(pipe_handle) continue if self.exit_loop: CloseHandle(pipe_handle) break if r == 0 and False: e = GetLastError() if e == ERROR_PIPE_CONNECTED: pass else: log.error("Error: cannot connect to named pipe '%s'", self.pipe_name) log.error(" error %s", e) CloseHandle(pipe_handle) continue #from now on, the pipe_handle will be managed elsewhere: self.new_connection_cb(self, pipe_handle)