Artifact
cf79848a6bd7d83d73a9fcca645b1fd4ab0d0177:
Attachment "winpipe.patch" to
ticket [3547994fff]
added by
ferrieux
2012-07-25 04:09:18.
0000: 49 6e 64 65 78 3a 20 77 69 6e 2f 74 63 6c 57 69 Index: win/tclWi
0010: 6e 50 69 70 65 2e 63 0a 3d 3d 3d 3d 3d 3d 3d 3d nPipe.c.========
0020: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
0030: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
0040: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
0050: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 0a 2d 2d 2d 20 ===========.---
0060: 77 69 6e 2f 74 63 6c 57 69 6e 50 69 70 65 2e 63 win/tclWinPipe.c
0070: 0a 2b 2b 2b 20 77 69 6e 2f 74 63 6c 57 69 6e 50 .+++ win/tclWinP
0080: 69 70 65 2e 63 0a 40 40 20 2d 31 38 37 33 2c 31 ipe.c.@@ -1873,1
0090: 36 20 2b 31 38 37 33 2c 33 30 20 40 40 0a 20 20 6 +1873,30 @@.
00a0: 20 20 20 7d 0a 20 20 20 20 20 69 66 20 28 28 21 }. if ((!
00b0: 66 6c 61 67 73 20 7c 7c 20 66 6c 61 67 73 20 26 flags || flags &
00c0: 20 54 43 4c 5f 43 4c 4f 53 45 5f 57 52 49 54 45 TCL_CLOSE_WRITE
00d0: 29 0a 20 09 20 20 20 20 26 26 20 28 70 69 70 65 ). . && (pipe
00e0: 50 74 72 2d 3e 77 72 69 74 65 46 69 6c 65 20 21 Ptr->writeFile !
00f0: 3d 20 4e 55 4c 4c 29 29 20 7b 0a 20 09 69 66 20 = NULL)) {. .if
0100: 28 70 69 70 65 50 74 72 2d 3e 77 72 69 74 65 54 (pipePtr->writeT
0110: 68 72 65 61 64 29 20 7b 0a 20 09 20 20 20 20 2f hread) {. . /
0120: 2a 0a 2d 09 20 20 20 20 20 2a 20 57 61 69 74 20 *.-. * Wait
0130: 66 6f 72 20 74 68 65 20 77 72 69 74 65 72 20 74 for the writer t
0140: 68 72 65 61 64 20 74 6f 20 66 69 6e 69 73 68 20 hread to finish
0150: 74 68 65 20 63 75 72 72 65 6e 74 20 62 75 66 66 the current buff
0160: 65 72 2c 20 74 68 65 6e 0a 2d 09 20 20 20 20 20 er, then.-.
0170: 2a 20 74 65 72 6d 69 6e 61 74 65 20 74 68 65 20 * terminate the
0180: 74 68 72 65 61 64 20 61 6e 64 20 63 6c 6f 73 65 thread and close
0190: 20 74 68 65 20 68 61 6e 64 6c 65 73 2e 20 49 66 the handles. If
01a0: 20 74 68 65 20 63 68 61 6e 6e 65 6c 20 69 73 0a the channel is.
01b0: 2d 09 20 20 20 20 20 2a 20 6e 6f 6e 62 6c 6f 63 -. * nonbloc
01c0: 6b 69 6e 67 2c 20 74 68 65 72 65 20 73 68 6f 75 king, there shou
01d0: 6c 64 20 62 65 20 6e 6f 20 70 65 6e 64 69 6e 67 ld be no pending
01e0: 20 77 72 69 74 65 20 6f 70 65 72 61 74 69 6f 6e write operation
01f0: 73 2e 0a 2b 09 20 20 20 20 20 2a 20 57 61 69 74 s..+. * Wait
0200: 20 66 6f 72 20 74 68 65 20 20 77 72 69 74 65 72 for the writer
0210: 20 74 68 72 65 61 64 20 74 6f 20 66 69 6e 69 73 thread to finis
0220: 68 20 74 68 65 20 20 63 75 72 72 65 6e 74 20 62 h the current b
0230: 75 66 66 65 72 2c 20 74 68 65 6e 0a 2b 09 20 20 uffer, then.+.
0240: 20 20 20 2a 20 74 65 72 6d 69 6e 61 74 65 20 74 * terminate t
0250: 68 65 20 74 68 72 65 61 64 20 20 61 6e 64 20 63 he thread and c
0260: 6c 6f 73 65 20 74 68 65 20 68 61 6e 64 6c 65 73 lose the handles
0270: 2e 20 49 66 20 20 74 68 65 20 63 68 61 6e 6e 65 . If the channe
0280: 6c 20 69 73 0a 2b 09 20 20 20 20 20 2a 20 6e 6f l is.+. * no
0290: 6e 62 6c 6f 63 6b 69 6e 67 20 62 75 74 20 62 6c nblocking but bl
02a0: 6f 63 6b 65 64 20 64 75 72 69 6e 67 20 20 65 78 ocked during ex
02b0: 69 74 2c 20 62 61 69 6c 20 6f 75 74 20 73 69 6e it, bail out sin
02c0: 63 65 20 74 68 65 20 77 6f 72 6b 65 72 0a 2b 09 ce the worker.+.
02d0: 20 20 20 20 20 2a 20 74 68 72 65 61 64 20 69 73 * thread is
02e0: 20 6e 6f 74 20 69 6e 74 65 72 72 75 70 74 69 62 not interruptib
02f0: 6c 65 20 61 6e 64 20 77 65 20 77 61 6e 74 20 54 le and we want T
0300: 49 50 23 33 39 38 2d 66 61 73 74 2d 65 78 69 74 IP#398-fast-exit
0310: 2e 0a 20 09 20 20 20 20 20 2a 2f 0a 2b 09 20 20 .. . */.+.
0320: 20 20 69 66 20 28 54 63 6c 49 6e 45 78 69 74 28 if (TclInExit(
0330: 29 0a 2b 09 09 26 26 20 28 70 69 70 65 50 74 72 ).+..&& (pipePtr
0340: 2d 3e 66 6c 61 67 73 20 26 20 50 49 50 45 5f 41 ->flags & PIPE_A
0350: 53 59 4e 43 29 29 20 7b 0a 20 0a 2d 09 20 20 20 SYNC)) {. .-.
0360: 20 57 61 69 74 46 6f 72 53 69 6e 67 6c 65 4f 62 WaitForSingleOb
0370: 6a 65 63 74 28 70 69 70 65 50 74 72 2d 3e 77 72 ject(pipePtr->wr
0380: 69 74 61 62 6c 65 2c 20 49 4e 46 49 4e 49 54 45 itable, INFINITE
0390: 29 3b 0a 2b 09 09 2f 2a 20 67 69 76 65 20 69 74 );.+../* give it
03a0: 20 61 20 63 68 61 6e 63 65 20 74 6f 20 6c 65 61 a chance to lea
03b0: 76 65 20 68 6f 6e 6f 72 61 62 6c 79 20 2a 2f 0a ve honorably */.
03c0: 2b 09 09 53 65 74 45 76 65 6e 74 28 70 69 70 65 +..SetEvent(pipe
03d0: 50 74 72 2d 3e 73 74 6f 70 57 72 69 74 65 72 29 Ptr->stopWriter)
03e0: 3b 0a 2b 0a 2b 09 09 69 66 20 28 57 61 69 74 46 ;.+.+..if (WaitF
03f0: 6f 72 53 69 6e 67 6c 65 4f 62 6a 65 63 74 28 70 orSingleObject(p
0400: 69 70 65 50 74 72 2d 3e 77 72 69 74 61 62 6c 65 ipePtr->writable
0410: 2c 20 30 29 20 3d 3d 20 57 41 49 54 5f 54 49 4d , 0) == WAIT_TIM
0420: 45 4f 55 54 29 20 7b 0a 2b 09 09 20 20 20 20 72 EOUT) {.+.. r
0430: 65 74 75 72 6e 20 45 41 47 41 49 4e 3b 0a 2b 09 eturn EAGAIN;.+.
0440: 09 7d 0a 2b 0a 2b 09 20 20 20 20 7d 20 65 6c 73 .}.+.+. } els
0450: 65 20 7b 0a 2b 0a 2b 09 09 57 61 69 74 46 6f 72 e {.+.+..WaitFor
0460: 53 69 6e 67 6c 65 4f 62 6a 65 63 74 28 70 69 70 SingleObject(pip
0470: 65 50 74 72 2d 3e 77 72 69 74 61 62 6c 65 2c 20 ePtr->writable,
0480: 49 4e 46 49 4e 49 54 45 29 3b 0a 2b 0a 2b 09 20 INFINITE);.+.+.
0490: 20 20 20 7d 0a 20 0a 20 09 20 20 20 20 2f 2a 0a }. . . /*.
04a0: 20 09 20 20 20 20 20 2a 20 54 68 65 20 74 68 72 . * The thr
04b0: 65 61 64 20 6d 61 79 20 61 6c 72 65 61 64 79 20 ead may already
04c0: 68 61 76 65 20 63 6c 6f 73 65 64 20 6f 6e 20 69 have closed on i
04d0: 74 27 73 20 6f 77 6e 2e 20 43 68 65 63 6b 20 69 t's own. Check i
04e0: 74 73 20 65 78 69 74 0a 20 09 20 20 20 20 20 2a ts exit. . *
04f0: 20 63 6f 64 65 2e 0a 20 09 20 20 20 20 20 2a 2f code.. . */
0500: 0a 40 40 20 2d 32 39 34 32 2c 31 30 20 2b 32 39 .@@ -2942,10 +29
0510: 35 36 2c 31 34 20 40 40 0a 20 09 69 66 20 28 77 56,14 @@. .if (w
0520: 61 69 74 52 65 73 75 6c 74 20 21 3d 20 28 57 41 aitResult != (WA
0530: 49 54 5f 4f 42 4a 45 43 54 5f 30 20 2b 20 31 29 IT_OBJECT_0 + 1)
0540: 29 20 7b 0a 20 09 20 20 20 20 2f 2a 0a 20 09 20 ) {. . /*. .
0550: 20 20 20 20 2a 20 54 68 65 20 73 74 61 72 74 20 * The start
0560: 65 76 65 6e 74 20 77 61 73 20 6e 6f 74 20 73 69 event was not si
0570: 67 6e 61 6c 65 64 2e 20 49 74 20 6d 69 67 68 74 gnaled. It might
0580: 20 62 65 20 74 68 65 20 73 74 6f 70 20 65 76 65 be the stop eve
0590: 6e 74 20 6f 72 0a 20 09 20 20 20 20 20 2a 20 61 nt or. . * a
05a0: 6e 20 65 72 72 6f 72 2c 20 73 6f 20 65 78 69 74 n error, so exit
05b0: 2e 0a 20 09 20 20 20 20 20 2a 2f 0a 2b 0a 2b 09 .. . */.+.+.
05c0: 20 20 20 20 69 66 20 28 77 61 69 74 52 65 73 75 if (waitResu
05d0: 6c 74 20 3d 3d 20 57 41 49 54 5f 4f 42 4a 45 43 lt == WAIT_OBJEC
05e0: 54 5f 30 29 20 7b 0a 2b 09 09 53 65 74 45 76 65 T_0) {.+..SetEve
05f0: 6e 74 28 69 6e 66 6f 50 74 72 2d 3e 77 72 69 74 nt(infoPtr->writ
0600: 61 62 6c 65 29 3b 0a 2b 09 20 20 20 20 7d 0a 20 able);.+. }.
0610: 0a 20 09 20 20 20 20 62 72 65 61 6b 3b 0a 20 09 . . break;. .
0620: 7d 0a 20 0a 20 09 62 75 66 20 3d 20 69 6e 66 6f }. . .buf = info
0630: 50 74 72 2d 3e 77 72 69 74 65 42 75 66 3b 0a 0a Ptr->writeBuf;..