Skip to content
Tcl Source Code Artifact [838d4d73fe]
Login

Artifact [838d4d73fe]

Artifact 838d4d73fe9ec3243053ede1497ec5e1498d7759bb8d91592e709dc74c4226f3:

Ticket change [838d4d73fe] - Ticket [de232b49f26da1c1|de232b49f2] <i>write-only nonblocking refchan and Tcl internal buffers</i> status still Open with 3 other changes by pooryorick on 2024-03-31 01:12:56.
D 2024-03-31T01:12:56.450
J icomment Yes,\sI\sincorrectly\sclaimed\sthat\s[chan\sconfigure\s...\s-blocking]\swas\r\nredundant\swith\s[socket\s-async].\sI\sforgot\sthat\s[socket\s-async]\sreturned\sa\r\nblocking\schannel.\s\s\sHowever,\sthe\sfact\sthat\s[socket\s-async]\sreturns\sa\r\nblocking\schannel\sprovides\sthe\ssolution\sto\s[080f846fd58958ef]:\s\sDon't\r\nimmediately\sconfigure\sthe\schannel\sto\sbe\snonblocking,\sand\sinstead\sdo\r\nthis:\r\n\r\n<code><verbatim>\r\n\tset\sso\s[twapi::tls_socket\s-async\swww.example.com\s443]\r\n\tfileevent\s$so\swritable\s[list\sapply\s{chan\s{\r\n\t\t#chan\sis\snow\sconnected\r\n\t\tfconfigure\s$so\s-blocking\s0\s\r\n\t\tfileevent\s$so\swritable\s[list\sapply\s{chan\s{\r\n\t\t\t#do\sstuff\swith\sconnected\schannel\r\n\t\t}\s$so]\r\n\t}}\s$so]\r\n\tvwait\s...\r\n</verbatim></code>\r\n\r\nProblem\ssolved:\s\sThe\sevent\swill\sbe\striggered\sonly\swhen\sthe\schannel\sis\r\nconnected.\s\sNow,\son\sto\sthe\sissue\sof\s"writable"\sevents\son\snon-blocking\r\nchannels.\s\sIf\sa\schannel\sexists\sand\sis\snonblocking,\sit's\swritable.\s\sAny\r\nother\sstate\sof\sthe\schannel,\swhether\sit\sis\serror\sstate\sor\sconnection\r\nstate\sis\snot\sa\sfactor.\s\sThat's\show\snonblocking\schannels\shave\salways\r\nfunctioned\sin\sTcl,\sand\sif\syou\sthink\sabout\sit,\sthat's\sthe\sway\sit\smust\sbe:\r\nIf\ssomething\sis\sblocking\sthe\swritability\sof\sa\schannel,\sthen\sit's\r\nno-longer\snonblocking.\s\sThat's\swhy\sit\shas\salways\sbeen\sthe\scase\sthat\sfor\r\na\snonblocking\schannel\s[puts]\snever\sfails,\sand\salso\swhy\s"Tcl\scontinues\sto\r\nbuffer\sthe\sdata\sand\swrites\sit\sin\sthe\sbackground\sas\sfast\sas\sthe\r\nunderlying\sfile\sor\sdevice\scan\saccept\sit."\s([puts]\sdocumentation),\sand\r\nwhy\s[close]\sis\sthe\soperation\sthat\sreports\sthe\serror,\sif\sthere\swas\sone:\r\nThere's\sno\sother\sstrategy\sthat\sis\spractical.\r\n\r\nHere's\sanother\sexample:\r\n\r\n<code><verbatim>\r\n\tset\schan\s[socket\s-async\s<some\saddress>]\r\n\tchan\sconfigure\s$chan\s-blocking\s0\r\n\tputs\s$chan\shello\r\n</verbatim></code>\r\n\r\nHere,\sit's\sentirely\spossible\sthat\sthe\ssocket\swill\snot\sbe\sconnected\syet,\r\nbut\swhen\s[puts]\sexecutes\sit\swill\snever\sfail,\snor\sshould\sit.\s\sThat's\sthe\r\npoint\sof\sconfiguring\sa\schannel\sto\sbe\snonblocking:\s\sIt\sdoesn't\sever\r\nblock.\s\sBy\sdefinition,\sif\sa\schannel\snever\sblocks,\sit\sis\salways\swritable.\r\nOver\sin\s[080f846fd58958ef]\sAshok\swrote,\s"Under\sno\scircumstances\sshould\sa\r\nfile\sevent\swritable\scallback\sbe\sinvoked\sunless\sthe\schannel\sis\sactually\r\nopen\s(writable)\sand\sthe\sabove\sdoes\snot\smake\sthat\scheck."\s\sAs\swe\ssee\sin\r\nthe\sexample\sabove,\sthat's\swrong:\s\s[puts]\sdoesn't\sfail,\sand\sif\sit\sdoesn't\r\nfail,\sthen\sthe\schannel\swas\swritable.\s\sIf\sthe\schannel\sis\swritable,\r\nthere's\sno\sproblem\striggering\sa\scorresponding\sevent\son\sthe\sthe\schannel.\r\nNot\sonly\sthat,\sbut\sthe\sfire-and-forget\saspect\sof\snonblocking\schannels\sis\r\nvery\sconvenient,\sparticularly\sat\sthe\sscript\slevel.\r\n\r\nI\sincorrectly\sclaimed\sthat\sthe\stest\s14.11.0\sfailure\swe\swere\stalking\r\nabout\swas\sthe\scase\swhere\sit\sproduces\san\serror.\s\sThe\sactual\ssituation\sis\r\nthat\sthe\stest\sfails\sif\san\serror\sdoes\snot\soccur,\sbut\sI\sbelieve\sit\sis\sby\r\ndesign\sthat\ssometimes\sthere\sis\sno\serror.\s\sThe\sdocumentation\sfor\s[close]\r\nstates,\r\n\r\n\s\s"If\sthe\schannel\sis\snonblocking\sand\sthere\sis\sunflushed\soutput,\sthe\r\n\s\schannel\sremains\sopen\sand\sthe\scommand\sreturns\simmediately;\soutput\swill\r\n\s\sbe\sflushed\sin\sthe\sbackground\sand\sthe\schannel\swill\sbe\sclosed\swhen\sall\r\n\s\sthe\sflushing\sis\scomplete."\r\n\r\nThat\smeans\sthat\sfor\ssystems\sthat\stake\stheir\ssweet\stime\sfiguring\sthat\sa\r\nconnection\scan't\sbe\scompleted,\s[close]\swill\sin\sthe\smeantime\sreturn\r\nwithout\serror,\swhich\sin\sturn\smeans\sthat\stest\s14.11.0\sis\sonly\stesting\r\ncircumstance\srather\sthan\sanything\smeaningful.\s\sPerhaps\sthat\stest\sshould\r\nbe\sdeleted,\sor\sperhaps\sa\spause\sshould\sbe\sintroduced\sto\slet\sthe\ssystem\r\nfinish\smeditating\son\sthe\sstate\sof\sthe\sconnection.\r\n\r\nI\sbelieve\sthat\sthe\sexisting\sfix\sfor\sthis\sissue\sis\stheoretically\scorrect,\r\nand\sshould\sremain\sin\splace.\s\sA\sfew\syears\sago\sI\ssubmitted\sissue\r\n[67a5eabbd3]\sand\sfixed\sit.\s\sPrior\sto\sthis,\srefchans\swere\sthoroughly\r\nbroken\sin\san\ssubtle\sway,\sand\sI\sbelieve\sthis\scaused\srefchan\sprogrammers\r\nover\sthe\syears\sto\sthrow\sup\stheir\shands\sand\sjust\swalk\saway\sfrom\srefchans,\r\nor\sto\sinvent\stwisted\scargo-cult\sapproaches\sto\skeeping\stheir\srefchans\r\nresponsive.\s\sThat\sissue\sis\srelated\sto\sthis\sone.\s\sNot\staking\sthe\sapproach\r\nthat\shas\snow\sbeen\sestablished\sfor\striggering\swritable\sevents\son\r\nasynchronous\schannels\srisks\smaking\sthem\sunusable\sagain\sin\sways\sthat\sare\r\ntoo\ssubtle\sfor\smost\sprogrammers\sto\sascertain,\sand\sin\smy\sexperience\smeans\r\nthat\swe'll\sjust\skeep\splaying\swhack-a-mole\swith\sissues\srelated\sto\r\nhandlers\snot\sever\sgetting\striggered\seven\sthough\sthe\sshould\sbe.\r\n\s\r\nI'm\snot\sin\sfavour\sof\schanging\sthe\sdefault\sbuffering\sfor\srefchans.\s\sThat\r\nwould\sbe\sa\sknee-jerk\sreaction\sto\sa\sparticular\sproblem\srather\sthan\sa\r\nwell-considered\sdesign,\sand\sin\sissue\s[080f846fd58958ef]\sthere\sis\sso\sfar\r\nno\sactual\sexample\sof\sa\sbroken\sscript\sthat\swould\swarrant\ssuch\sa\schange.
J login pooryorick
J mimetype text/x-fossil-wiki
K de232b49f26da1c18e07513d4c7caa203cd27910
U pooryorick
Z f6189d931c5c6797d76a00462318639e