.
D 2000-10-26T00:47:01
J assignee nobody
J cmimetype text/plain
J comment OriginalBugID:\s5339\sRFE\nVersion:\s8.0.4\nSubmitDate:\s'2000-05-03'\nLastModified:\s'2000-05-04'\nSeverity:\sMED\nStatus:\sClosed\nSubmitter:\stechsupp\nChangedBy:\shobbs\nRelatedBugIDs:\s1429\nOS:\sSolaris\nOSVersion:\sSolaris\s2.6\nMachine:\sStandard\sSun\sUltraSparc\sarchitecture\nFixedDate:\s'2000-10-25'\nClosedDate:\s'2000-05-04'\n\n\nName:\sKevin\sL.\sSitze\n\nDesiredBehavior:\nThere\sare\stimes\swhen\sa\sTcl\sscript\sneeds\sto\sbe\sable\sto\sshutdown\sonly\none\sside\sof\sa\schannel.\s\sCurrently\sTcl\sdoes\snot\sallow\sthis\nfunctionality.\s\sHere\sis\san\sexample\sof\show\sthis\scan\scause\sproblems.\n\nIf\sa\sTcl\sscript\ssets\sup\sa\spipeline\swherein\sit\sis\sboth\sthe\sconsumer\sand\nthe\sproducer,\sit\sis\sincapable\sof\sproperly\scleaning\sup\sbecause\sit\ndoesn't\sknow\swhen\sto\sclose\sthe\schannel.\s\sIt\scannot\sdetect\sthe\sEOF\son\nthe\schannel\sbecause\sit\smust\sfirst\ssend\san\sEOF\sto\sthe\schannel,\swhich\sit\ncannot\sdo\swithout\sresorting\sto\sC.\n\nHere's\ssome\sexample\scode.\n\n#!\s/usr/local/bin/tclsh\n\n####\n#\s\sThis\sis\sjust\sto\sget\sthe\sdata,\sthe\sdata\smay\sbe\sproduced\n#\s\sin\ssome\sfashion\s(say,\spulled\sfrom\san\sinternal\sdatabase)\n#\s\swhich\sprevents\sus\sfrom\s\n\nset\sfname\s"some.tar.gz"\nset\sfd\s[open\s$fname\s"r"]\nset\sgzdata\s[read\s$fd\s[file\ssize\s$fname]]\nclose\s$fd\n\n####\n#\s\sSimple\scallback\sfor\spushing\spipe\soutput\sto\sstdout.\n\nproc\sgzrecv\s{fd}\s{\n\s\s\s\swhile\s{[gets\s$fd\sline]\s>\s0}\s{\nputs\s$line\n\s\s\s\s}\n\n\s\s\s\sif\s{[eof\s$fd]}\s{\nglobal\sforever\nset\sforever\strue\n\s\s\s\s}\n}\n\n####\n#\s\sSetup\sthe\sprocessing\spipeline.\n\nset\sgunzip\s[open\s"|\sgunzip\s|\star\stf\s-"\s"r+"]\nfileevent\s$gunzip\sreadable\s"gzrecv\s$gunzip"\nfconfigure\s$gunzip\s-blocking\sfalse\n\nputs\s$gunzip\s$gzdata\nset\sforever\sfalse\nvwait\sforever\n\n####\n#\s\sMust\sclose\ssocket\safter\sdata\shas\sbeen\sread.\n\nclose\s$gunzip\n\nexit\s0\n\nThere\sare\sactually\stwo\sproblems\shere.\s\sThe\sfirst\sproblem\sis\sin\sthe\n"fconfigure\s$gunzip\s-blocking\sfalse"\sstatement.\s\sSetting\sthis\sfile\ndescriptor\sin\snon-blocking\smode\sapparently\scauses\s"EAGAIN"\serrors\sto\nbe\sreturned\sfrom\sthe\s"gunzip"\scommand\s(I\sdon't\sunderstand\swhy,\sbut\sit\ndoes,\son\sSolaris\sanyway).\s\sThis\scommand\sexpects\sa\sblocking\ssocket\sand\ndoesn't\shandle\sthis\serror\sproperly,\seventually\scausing\sthe\sapplication\nto\sexit\sincorrectly.\n\nThe\ssecond\sproblem\sis:\swhen\sdoes\sthe\sEOF\sget\sto\sthe\soutput\sside\sof\sthe\nsocket?\s\sTypically,\sthe\sEOF\spropagates\sthrough\sthe\spipeline\sfrom\sthe\nproducer\s(writer)\sto\sthe\sconsumer\s(reader).\s\sAs\sTcl\sviews\sa\spipeline\nchannel\sas\sa\ssingle\sfile,\sthere\sis\sno\sway\swhereby\sa\spipeline\sis\ncapable\sof\sclosing\sdown\sits\sinput\swithout\salso\sclosing\sdown\sits\soutput\n(which\smay\sstill\shave\sdata\spending\sin\sthe\spipeline).\n\nThere\sare\sseveral\sworkarounds:\n1)\s\sSpawn\soff\sa\ssecondary\sscript\sto\sact\sas\seither\sthe\sproducer\sor\n\s\s\s\sconsumer\s(as\smay\sbe\srequired).\n2)\s\sGenerate\sa\sC\shack\sto\sperform\sthe\sshutdown.\n3)\s\sWrite\sthe\sdata\sinto\sa\stemporary\sfile\sand\sfeed\sthe\spipeline\son\n\s\s\s\sthis\sfile.\s\sThis\smay\sresult\sin\scertain\sperformance\sissues\sif\n\s\s\s\sattempting\sto\srun\sin\sreal\stime.\n\nThe\spreferred\ssolution\sis\sto\sprovide\sa\sTcl\scommand\swhich\sallows\nsplitting\sa\ssingle\sread/write\schannel\sinto\stwo\schannels.\s\sOne\sfor\nreading\sand\sone\sfor\swriting.\n\n\s\s\s\sset\srwlist\s[fsplit\s$channel]\n\s\s\s\sset\srecvfd\s[lindex\s$rwlist\s0]\n\s\s\s\sset\ssendfd\s[lindex\s$rwlist\s1]\n\nIt\sis\sdebatable\sas\sto\swhether\sthe\soriginal\schannel\sis\svalid\safter\nsplitting\sit\sout\sin\sthis\sfashion.\n\nThe\salternate\ssolution\sis\sto\smodify\sthe\s"fconfigure"\sand\s"close"\ncommands\sto\sallow\sfor\sperforming\scertain\soperations\son\sonly\sone\s"side"\nof\sthe\schannel.\s\sSomething\slike:\n\n\s\s\s\sfconfigure\s$fd\s-side\sread\s-blocking\sfalse\n\s\s\s\sclose\s-side\swrite\s$fd\n\nThe\sabove\scode\scould\sthen\sbe\swritten:\n\n#!\s/usr/local/bin/tclsh\n\n####\n#\s\sThis\sis\sjust\sto\sget\sthe\sdata,\sthe\sdata\smay\sbe\sproduced\n#\s\sin\ssome\sfashion\s(say,\spulled\sfrom\san\sinternal\sdatabase)\n#\s\swhich\sprevents\sus\sfrom\s\n\nset\sfname\s"some.tar.gz"\nset\sfd\s[open\s$fname\s"r"]\nset\sgzdata\s[read\s$fd\s[file\ssize\s$fname]]\nclose\s$fd\n\n####\n#\s\sSimple\scallback\sfor\spushing\spipe\soutput\sto\sstdout.\n\nproc\sgzrecv\s{fd}\s{\n\s\s\s\swhile\s{[gets\s$fd\sline]\s>\s0}\s{\nputs\s$line\n\s\s\s\s}\n\n\s\s\s\sif\s{[eof\s$fd]}\s{\nglobal\sforever\nset\sforever\strue\n\s\s\s\s}\n}\n\n####\n#\s\sSetup\sthe\sprocessing\spipeline.\n\nset\sgunzip\s[open\s"|\sgunzip\s|\star\stf\s-"\s"r+"]\nfconfigure\s$gunzip\s-side\sread\s-blocking\sfalse\nfileevent\s$gunzip\sreadable\s"gzrecv\s$gunzip"\n\nputs\s$gunzip\s$gzdata\nclose\s-side\swrite\s$gunzip\nset\sforever\sfalse\nvwait\sforever\n\n####\n#\s\sMust\sclose\ssocket\safter\sdata\shas\sbeen\sread.\n\nclose\s$gunzip\n\nexit\s0\n\nNote\sthat\ssuch\soperations\sare\salso\suseful\sfor\shandling\ssocket\nchannels.\s\sThe\sshutdown(3n)\sinterface\sallows\sone\send\sof\sthe\nfile/socket\sdescriptor\sto\sbe\sclosed.\s\sThis\sfunctionality\scan\sbe\suseful\nin\shandling\sadvanced\sTcl\sclient/server\sproblems.\n\n\n\n
J foundin obsolete:\s8.0.4
J priority 5\sMedium
J resolution None
J status Open
J submitter nobody
J subsystem 63.\s(unused)
J title Shutdown\sone\sside\sof\sa\ssocket/pipe\schannel.
J type Bug
K 217976ffffffffffffffffffffffffffffffffff
U nobody
Z 7487202ce96f68057ce9d361bdf3ae81