Artifact
085d26018a3df2447faa3e58715220bbaedb7062eece7b3ea91a66ff8009e707:
Attachment "FlushChannelPatch.txt" to
ticket [d481f15516]
added by
anonymous
2020-01-05 14:51:19.
0000: 49 6e 64 65 78 3a 20 67 65 6e 65 72 69 63 2f 74 Index: generic/t
0010: 63 6c 49 4f 2e 63 0a 3d 3d 3d 3d 3d 3d 3d 3d 3d clIO.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 0a 2d 2d 2d 20 67 65 =========.--- ge
0060: 6e 65 72 69 63 2f 74 63 6c 49 4f 2e 63 0a 2b 2b neric/tclIO.c.++
0070: 2b 20 67 65 6e 65 72 69 63 2f 74 63 6c 49 4f 2e + generic/tclIO.
0080: 63 0a 40 40 20 2d 33 32 34 39 2c 31 30 20 2b 33 c.@@ -3249,10 +3
0090: 32 34 39 2c 31 34 20 40 40 0a 20 09 70 72 65 76 249,14 @@. .prev
00a0: 43 53 50 74 72 2d 3e 6e 65 78 74 43 53 50 74 72 CSPtr->nextCSPtr
00b0: 20 3d 20 73 74 61 74 65 50 74 72 2d 3e 6e 65 78 = statePtr->nex
00c0: 74 43 53 50 74 72 3b 0a 20 20 20 20 20 7d 0a 20 tCSPtr;. }.
00d0: 0a 20 20 20 20 20 73 74 61 74 65 50 74 72 2d 3e . statePtr->
00e0: 6e 65 78 74 43 53 50 74 72 20 3d 20 4e 55 4c 4c nextCSPtr = NULL
00f0: 3b 0a 20 0a 2b 20 20 20 20 2f 2a 20 43 68 61 6e ;. .+ /* Chan
0100: 6e 65 6c 20 69 73 20 6e 6f 74 20 6d 61 6e 61 67 nel is not manag
0110: 65 64 20 62 79 20 61 6e 79 20 74 68 72 65 61 64 ed by any thread
0120: 20 2a 2f 0a 2b 20 20 20 20 73 74 61 74 65 50 74 */.+ statePt
0130: 72 2d 3e 6d 61 6e 61 67 69 6e 67 54 68 72 65 61 r->managingThrea
0140: 64 20 3d 20 4e 55 4c 4c 3b 0a 2b 20 20 20 20 55 d = NULL;.+ U
0150: 70 64 61 74 65 49 6e 74 65 72 65 73 74 28 63 68 pdateInterest(ch
0160: 61 6e 50 74 72 29 3b 0a 2b 0a 20 20 20 20 20 2f anPtr);.+. /
0170: 2a 0a 20 20 20 20 20 20 2a 20 54 49 50 20 23 32 *. * TIP #2
0180: 31 38 2c 20 43 68 61 6e 6e 65 6c 20 54 68 72 65 18, Channel Thre
0190: 61 64 20 41 63 74 69 6f 6e 73 0a 20 20 20 20 20 ad Actions.
01a0: 20 2a 20 46 6f 72 20 61 6c 6c 20 74 72 61 6e 73 * For all trans
01b0: 66 6f 72 6d 61 74 69 6f 6e 73 20 61 6e 64 20 74 formations and t
01c0: 68 65 20 62 61 73 65 20 63 68 61 6e 6e 65 6c 2e he base channel.
01d0: 0a 20 20 20 20 20 20 2a 2f 0a 20 0a 40 40 20 2d . */. .@@ -
01e0: 33 33 33 38 2c 31 30 20 2b 33 33 34 32 2c 31 31 3338,10 +3342,11
01f0: 20 40 40 0a 20 20 20 20 20 20 2a 09 09 4e 6f 74 @@. *..Not
0200: 65 3a 20 27 54 63 6c 5f 47 65 74 43 75 72 72 65 e: 'Tcl_GetCurre
0210: 6e 74 54 68 72 65 61 64 27 20 72 65 74 75 72 6e ntThread' return
0220: 73 20 73 65 6e 73 69 62 6c 65 20 76 61 6c 75 65 s sensible value
0230: 73 20 65 76 65 6e 20 66 6f 72 0a 20 20 20 20 20 s even for.
0240: 20 2a 09 09 61 20 6e 6f 6e 2d 74 68 72 65 61 64 *..a non-thread
0250: 65 64 20 63 6f 72 65 2e 0a 20 20 20 20 20 20 2a ed core.. *
0260: 2f 0a 20 0a 20 20 20 20 20 73 74 61 74 65 50 74 /. . statePt
0270: 72 2d 3e 6d 61 6e 61 67 69 6e 67 54 68 72 65 61 r->managingThrea
0280: 64 20 3d 20 54 63 6c 5f 47 65 74 43 75 72 72 65 d = Tcl_GetCurre
0290: 6e 74 54 68 72 65 61 64 28 29 3b 0a 2b 20 20 20 ntThread();.+
02a0: 20 55 70 64 61 74 65 49 6e 74 65 72 65 73 74 28 UpdateInterest(
02b0: 63 68 61 6e 50 74 72 29 3b 0a 20 0a 20 20 20 20 chanPtr);. .
02c0: 20 2f 2a 0a 20 20 20 20 20 20 2a 20 54 49 50 20 /*. * TIP
02d0: 23 32 31 38 2c 20 43 68 61 6e 6e 65 6c 20 54 68 #218, Channel Th
02e0: 72 65 61 64 20 41 63 74 69 6f 6e 73 0a 20 20 20 read Actions.
02f0: 20 20 20 2a 20 46 6f 72 20 61 6c 6c 20 74 72 61 * For all tra
0300: 6e 73 66 6f 72 6d 61 74 69 6f 6e 73 20 61 6e 64 nsformations and
0310: 20 74 68 65 20 62 61 73 65 20 63 68 61 6e 6e 65 the base channe
0320: 6c 2e 0a 20 20 20 20 20 20 2a 2f 0a 0a 49 6e 64 l.. */..Ind
0330: 65 78 3a 20 75 6e 69 78 2f 74 63 6c 55 6e 69 78 ex: unix/tclUnix
0340: 53 6f 63 6b 2e 63 0a 3d 3d 3d 3d 3d 3d 3d 3d 3d Sock.c.=========
0350: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
0360: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
0370: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
0380: 3d 3d 3d 3d 3d 3d 3d 3d 3d 0a 2d 2d 2d 20 75 6e =========.--- un
0390: 69 78 2f 74 63 6c 55 6e 69 78 53 6f 63 6b 2e 63 ix/tclUnixSock.c
03a0: 0a 2b 2b 2b 20 75 6e 69 78 2f 74 63 6c 55 6e 69 .+++ unix/tclUni
03b0: 78 53 6f 63 6b 2e 63 0a 40 40 20 2d 31 32 37 2c xSock.c.@@ -127,
03c0: 31 30 20 2b 31 32 37 2c 31 31 20 40 40 0a 20 0a 10 +127,11 @@. .
03d0: 20 2f 2a 0a 20 20 2a 20 53 74 61 74 69 63 20 72 /*. * Static r
03e0: 6f 75 74 69 6e 65 73 20 66 6f 72 20 74 68 69 73 outines for this
03f0: 20 66 69 6c 65 3a 0a 20 20 2a 2f 0a 20 0a 2b 73 file:. */. .+s
0400: 74 61 74 69 63 20 76 6f 69 64 09 09 54 63 70 41 tatic void..TcpA
0410: 73 79 6e 63 43 61 6c 6c 62 61 63 6b 28 43 6c 69 syncCallback(Cli
0420: 65 6e 74 44 61 74 61 20 63 6c 69 65 6e 74 44 61 entData clientDa
0430: 74 61 2c 20 69 6e 74 20 6d 61 73 6b 29 3b 0a 20 ta, int mask);.
0440: 73 74 61 74 69 63 20 69 6e 74 09 09 54 63 70 43 static int..TcpC
0450: 6f 6e 6e 65 63 74 28 54 63 6c 5f 49 6e 74 65 72 onnect(Tcl_Inter
0460: 70 20 2a 69 6e 74 65 72 70 2c 20 54 63 70 53 74 p *interp, TcpSt
0470: 61 74 65 20 2a 73 74 61 74 65 29 3b 0a 20 73 74 ate *state);. st
0480: 61 74 69 63 20 76 6f 69 64 09 09 54 63 70 41 63 atic void..TcpAc
0490: 63 65 70 74 28 43 6c 69 65 6e 74 44 61 74 61 20 cept(ClientData
04a0: 64 61 74 61 2c 20 69 6e 74 20 6d 61 73 6b 29 3b data, int mask);
04b0: 0a 20 73 74 61 74 69 63 20 69 6e 74 09 09 54 63 . static int..Tc
04c0: 70 42 6c 6f 63 6b 4d 6f 64 65 50 72 6f 63 28 43 pBlockModeProc(C
04d0: 6c 69 65 6e 74 44 61 74 61 20 64 61 74 61 2c 20 lientData data,
04e0: 69 6e 74 20 6d 6f 64 65 29 3b 0a 20 73 74 61 74 int mode);. stat
04f0: 69 63 20 69 6e 74 09 09 54 63 70 43 6c 6f 73 65 ic int..TcpClose
0500: 50 72 6f 63 28 43 6c 69 65 6e 74 44 61 74 61 20 Proc(ClientData
0510: 69 6e 73 74 61 6e 63 65 44 61 74 61 2c 0a 20 09 instanceData,. .
0520: 09 09 20 20 20 20 54 63 6c 5f 49 6e 74 65 72 70 .. Tcl_Interp
0530: 20 2a 69 6e 74 65 72 70 29 3b 0a 40 40 20 2d 31 *interp);.@@ -1
0540: 30 36 30 2c 31 30 20 2b 31 30 36 31 2c 33 36 20 060,10 +1061,36
0550: 40 40 0a 20 20 20 20 20 20 20 20 20 20 2a 20 41 @@. * A
0560: 73 79 6e 63 20 73 6f 63 6b 65 74 73 20 75 73 65 sync sockets use
0570: 20 61 20 46 69 6c 65 48 61 6e 64 6c 65 72 20 69 a FileHandler i
0580: 6e 74 65 72 6e 61 6c 6c 79 20 77 68 69 6c 65 20 nternally while
0590: 63 6f 6e 6e 65 63 74 69 6e 67 2c 20 73 6f 20 77 connecting, so w
05a0: 65 0a 20 20 20 20 20 20 20 20 20 20 2a 20 6e 65 e. * ne
05b0: 65 64 20 74 6f 20 63 61 63 68 65 20 74 68 69 73 ed to cache this
05c0: 20 72 65 71 75 65 73 74 20 75 6e 74 69 6c 20 74 request until t
05d0: 68 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 68 61 he connection ha
05e0: 73 20 73 75 63 63 65 65 64 65 64 2e 0a 20 20 20 s succeeded..
05f0: 20 20 20 20 20 20 20 2a 2f 0a 20 0a 20 20 20 20 */. .
0600: 20 20 20 20 20 73 74 61 74 65 50 74 72 2d 3e 66 statePtr->f
0610: 69 6c 65 68 61 6e 64 6c 65 72 73 20 3d 20 6d 61 ilehandlers = ma
0620: 73 6b 3b 0a 2b 0a 2b 09 2f 2a 0a 2b 09 20 2a 20 sk;.+.+./*.+. *
0630: 52 65 6d 6f 76 65 20 74 68 65 20 46 69 6c 65 48 Remove the FileH
0640: 61 6e 64 6c 65 72 20 69 66 20 74 68 65 20 73 6f andler if the so
0650: 63 6b 65 74 20 69 73 20 6e 6f 74 20 6d 61 6e 61 cket is not mana
0660: 67 65 64 20 62 79 20 61 6e 79 20 74 68 72 65 61 ged by any threa
0670: 64 0a 2b 09 20 2a 20 4f 74 68 65 72 77 69 73 65 d.+. * Otherwise
0680: 20 74 68 65 20 68 61 6e 64 6c 65 72 20 69 73 20 the handler is
0690: 6c 69 6b 65 6c 79 20 74 6f 20 72 75 6e 20 69 6e likely to run in
06a0: 20 74 68 65 20 77 72 6f 6e 67 20 74 68 72 65 61 the wrong threa
06b0: 64 2c 0a 2b 09 20 2a 20 70 6f 73 73 69 62 6c 79 d,.+. * possibly
06c0: 20 6c 65 61 64 69 6e 67 20 74 6f 20 61 6c 6c 20 leading to all
06d0: 6b 69 6e 64 73 20 6f 66 20 75 67 6c 79 20 69 73 kinds of ugly is
06e0: 73 75 65 73 2e 0a 2b 09 20 2a 2f 0a 2b 0a 2b 09 sues..+. */.+.+.
06f0: 69 66 20 28 21 54 63 6c 5f 47 65 74 43 68 61 6e if (!Tcl_GetChan
0700: 6e 65 6c 54 68 72 65 61 64 28 73 74 61 74 65 50 nelThread(stateP
0710: 74 72 2d 3e 63 68 61 6e 6e 65 6c 29 29 20 7b 0a tr->channel)) {.
0720: 2b 09 20 20 20 20 43 4c 45 41 52 5f 42 49 54 53 +. CLEAR_BITS
0730: 28 73 74 61 74 65 50 74 72 2d 3e 66 6c 61 67 73 (statePtr->flags
0740: 2c 20 54 43 50 5f 41 53 59 4e 43 5f 50 45 4e 44 , TCP_ASYNC_PEND
0750: 49 4e 47 29 3b 0a 2b 09 20 20 20 20 54 63 6c 5f ING);.+. Tcl_
0760: 44 65 6c 65 74 65 46 69 6c 65 48 61 6e 64 6c 65 DeleteFileHandle
0770: 72 28 73 74 61 74 65 50 74 72 2d 3e 66 64 73 2e r(statePtr->fds.
0780: 66 64 29 3b 0a 2b 09 7d 0a 2b 20 20 20 20 7d 20 fd);.+.}.+ }
0790: 65 6c 73 65 20 69 66 20 28 47 4f 54 5f 42 49 54 else if (GOT_BIT
07a0: 53 28 73 74 61 74 65 50 74 72 2d 3e 66 6c 61 67 S(statePtr->flag
07b0: 73 2c 20 54 43 50 5f 41 53 59 4e 43 5f 43 4f 4e s, TCP_ASYNC_CON
07c0: 4e 45 43 54 29 29 20 7b 0a 2b 0a 2b 09 2f 2a 0a NECT)) {.+.+./*.
07d0: 2b 09 20 2a 20 41 6e 20 61 73 79 6e 63 20 73 6f +. * An async so
07e0: 63 6b 65 74 20 77 69 74 68 6f 75 74 20 61 6e 20 cket without an
07f0: 61 73 79 6e 63 20 65 76 65 6e 74 20 70 65 6e 64 async event pend
0800: 69 6e 67 20 6d 75 73 74 20 6a 75 73 74 20 68 61 ing must just ha
0810: 76 65 20 62 65 65 6e 0a 2b 09 20 2a 20 74 72 61 ve been.+. * tra
0820: 6e 73 66 65 72 72 65 64 20 66 72 6f 6d 20 61 6e nsferred from an
0830: 6f 74 68 65 72 20 74 68 72 65 61 64 2e 20 52 65 other thread. Re
0840: 65 73 74 61 62 6c 69 73 68 20 74 68 65 20 46 69 establish the Fi
0850: 6c 65 48 61 6e 64 6c 65 72 20 68 65 72 65 0a 2b leHandler here.+
0860: 09 20 2a 20 73 6f 20 74 68 65 20 63 61 6c 6c 62 . * so the callb
0870: 61 63 6b 20 77 69 6c 6c 20 72 75 6e 20 69 6e 20 ack will run in
0880: 74 68 65 20 63 6f 72 72 65 63 74 20 74 68 72 65 the correct thre
0890: 61 64 2e 0a 2b 09 20 2a 2f 0a 2b 0a 2b 09 54 63 ad..+. */.+.+.Tc
08a0: 6c 5f 43 72 65 61 74 65 46 69 6c 65 48 61 6e 64 l_CreateFileHand
08b0: 6c 65 72 28 73 74 61 74 65 50 74 72 2d 3e 66 64 ler(statePtr->fd
08c0: 73 2e 66 64 2c 0a 2b 09 09 09 20 20 20 20 20 20 s.fd,.+...
08d0: 54 43 4c 5f 57 52 49 54 41 42 4c 45 20 7c 20 54 TCL_WRITABLE | T
08e0: 43 4c 5f 45 58 43 45 50 54 49 4f 4e 2c 20 54 63 CL_EXCEPTION, Tc
08f0: 70 41 73 79 6e 63 43 61 6c 6c 62 61 63 6b 2c 0a pAsyncCallback,.
0900: 2b 09 09 09 20 20 20 20 20 20 73 74 61 74 65 50 +... stateP
0910: 74 72 29 3b 0a 2b 09 53 45 54 5f 42 49 54 53 28 tr);.+.SET_BITS(
0920: 73 74 61 74 65 50 74 72 2d 3e 66 6c 61 67 73 2c statePtr->flags,
0930: 20 54 43 50 5f 41 53 59 4e 43 5f 50 45 4e 44 49 TCP_ASYNC_PENDI
0940: 4e 47 29 3b 0a 2b 0a 2b 09 2f 2a 20 43 61 63 68 NG);.+.+./* Cach
0950: 65 20 74 68 65 20 63 75 72 72 65 6e 74 20 72 65 e the current re
0960: 71 75 65 73 74 20 75 6e 74 69 6c 20 74 68 65 20 quest until the
0970: 63 6f 6e 6e 65 63 74 69 6f 6e 20 68 61 73 20 73 connection has s
0980: 75 63 63 65 65 64 65 64 20 2a 2f 0a 2b 09 73 74 ucceeded */.+.st
0990: 61 74 65 50 74 72 2d 3e 66 69 6c 65 68 61 6e 64 atePtr->filehand
09a0: 6c 65 72 73 20 3d 20 6d 61 73 6b 3b 0a 20 20 20 lers = mask;.
09b0: 20 20 7d 20 65 6c 73 65 20 69 66 20 28 6d 61 73 } else if (mas
09c0: 6b 29 20 7b 0a 20 0a 20 09 2f 2a 0a 20 09 20 2a k) {. . ./*. . *
09d0: 20 57 68 65 74 68 65 72 20 69 74 20 69 73 20 61 Whether it is a
09e0: 20 62 75 67 20 6f 72 20 66 65 61 74 75 72 65 20 bug or feature
09f0: 6f 72 20 6f 74 68 65 72 77 69 73 65 2c 20 69 74 or otherwise, it
0a00: 20 69 73 20 61 20 66 61 63 74 20 6f 66 20 6c 69 is a fact of li
0a10: 66 65 0a 20 09 20 2a 20 74 68 61 74 20 6f 6e 20 fe. . * that on
0a20: 61 74 20 6c 65 61 73 74 20 73 6f 6d 65 20 4c 69 at least some Li
0a30: 6e 75 78 20 6b 65 72 6e 65 6c 73 20 73 65 6c 65 nux kernels sele
0a40: 63 74 28 29 20 66 61 69 6c 73 20 74 6f 20 72 65 ct() fails to re
0a50: 70 6f 72 74 20 74 68 61 74 20 61 0a 0a port that a..