'internal close port helper'

def _close(self):

    if (self._port_handle is not None):
        win32.SetCommTimeouts(self._port_handle, self._orgTimeouts)
        if (self._overlapped_read is not None):
            self.cancel_read()
            win32.CloseHandle(self._overlapped_read.hEvent)
            self._overlapped_read = None
        if (self._overlapped_write is not None):
            self.cancel_write()
            win32.CloseHandle(self._overlapped_write.hEvent)
            self._overlapped_write = None
        win32.CloseHandle(self._port_handle)
        self._port_handle = None
