summaryrefslogtreecommitdiffstats
path: root/win/tclWinSerial.c
diff options
context:
space:
mode:
authoroehhar <harald.oehlmann@elmicron.de>2014-01-30 11:02:51 (GMT)
committeroehhar <harald.oehlmann@elmicron.de>2014-01-30 11:02:51 (GMT)
commitd7757d423e285ae0c112407d1dcc60191aa0b4bd (patch)
treed575677dcd6766a1044753f84cdbc788f010e1ac /win/tclWinSerial.c
parent9d0cf098518e48651256d556d750716978ea57df (diff)
downloadtcl-d7757d423e285ae0c112407d1dcc60191aa0b4bd.zip
tcl-d7757d423e285ae0c112407d1dcc60191aa0b4bd.tar.gz
tcl-d7757d423e285ae0c112407d1dcc60191aa0b4bd.tar.bz2
win/tclWinChan.c Tcl_InitNotifier: Bug [2413550] Avoid reopening of serial channels which causes issues with Bluetooth virtual com. Patch by Rolf Schroedter.
Diffstat (limited to 'win/tclWinSerial.c')
-rw-r--r--win/tclWinSerial.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/win/tclWinSerial.c b/win/tclWinSerial.c
index d5244ac..312a2f8 100644
--- a/win/tclWinSerial.c
+++ b/win/tclWinSerial.c
@@ -1410,23 +1410,22 @@ SerialWriterThread(
/*
*----------------------------------------------------------------------
*
- * TclWinSerialReopen --
+ * TclWinSerialOpen --
*
- * Reopens the serial port with the OVERLAPPED FLAG set
+ * Opens or Reopens the serial port with the OVERLAPPED FLAG set
*
* Results:
- * Returns the new handle, or INVALID_HANDLE_VALUE. Normally there
- * shouldn't be any error, because the same channel has previously been
- * succeesfully opened.
+ * Returns the new handle, or INVALID_HANDLE_VALUE.
+ * I an existing channel is specified it is closed and reopened.
*
* Side effects:
- * May close the original handle
+ * May close/reopen the original handle
*
*----------------------------------------------------------------------
*/
HANDLE
-TclWinSerialReopen(
+TclWinSerialOpen(
HANDLE handle,
CONST TCHAR *name,
DWORD access)
@@ -1434,16 +1433,22 @@ TclWinSerialReopen(
SerialInit();
/*
+ * If an open channel is specified, close it
+ */
+
+ if ( handle != INVALID_HANDLE_VALUE && CloseHandle(handle) == FALSE) {
+ return INVALID_HANDLE_VALUE;
+ }
+
+ /*
* Multithreaded I/O needs the overlapped flag set otherwise
* ClearCommError blocks under Windows NT/2000 until serial output is
* finished
*/
- if (CloseHandle(handle) == FALSE) {
- return INVALID_HANDLE_VALUE;
- }
handle = (*tclWinProcs->createFileProc)(name, access, 0, 0,
OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
+
return handle;
}