Skip to content
Tcl Source Code Artifact [3daba3b279]
Login

Artifact [3daba3b279]

Artifact 3daba3b2797c3a64cbb010dc8422e83a469c16e3:

Ticket change [3daba3b279] - Ticket [780533ffffffffff|780533ffff] <i>[fcopy] callback sometimes fails to trigger</i> status still Open with 4 other changes by ferrieux on 2008-04-01 00:14:32.
D 2008-04-01T00:14:32
J icomment Logged\sIn:\sYES\s\nuser_id=496139\nOriginator:\sNO\n\nFound\sand\sfixed.\sThis\swas\sa\sday-1\sbug...\n\nBug\ssummary:\sdoing\san\sasync\s[fcopy\s-size\s$size],\sif\sthe\sinput\sstalls\s(not\sEOF)\safter\sexactly\s$size\sbytes,\sthe\scallback\sis\snot\scalled.\n\nThe\sproblem\sis\sin\sthe\sCopyData\sfunction,\snear\sthe\send\sof\sthe\nwhile(toRead)\sloop,\sin\sthe\sif\s(cmdPtr)\sblock.\sApply\sthe\sfollowing\npatch:\n\n-\s\s\s\s\s\s\sif\s(cmdPtr)\s{\n+\s\s\s\s\s\s\sif\s(cmdPtr\s&&(csPtr->toRead\s!=\s0))\s{\n\s\s\s\s\s\s\s\s\s\s\s/*\n\s\s\s\s\s\s\s\s\s\s\s\s*\sThe\sfirst\stime\swe\senter\sthis\scode,\sthere\swon't\sbe\sa\schannel\n\s\s\s\s\s\s\s\s\s\s\s\s*\shandler\sestablished\syet,\sso\sdo\sit\shere.\n\s\s\s\s\s\s\s\s\s\s\s\s*/\n\nExplanation:\sthis\stest\sis\shere\sto\s"break\sout"\sof\sthe\sentire\sroutine\n(not\sjust\sthe\swhile\sloop)\swith\sa\sreturn\sTCL_OK,\sin\sasync\smode,\safter\nmaking\ssure\swe\shave\sa\sfileevent\sto\swake\sus\sup\slater.\sThe\sproblem\sis\nthat\sat\sthis\sspot\sthe\sremaining\snumber\sof\sbytes\sto\sread\sdue\sto\s[-size]\nhas\salready\sbeen\supdated,\sand\swhen\sit\sreaches\szero,\swe\sshould\sonly\nbreak\sof\sthe\swhile\sloop\sin\sorder\sto\sterminate\sproperly\s(and\scall\sthe\ncallback).\n\nHence\sthe\sfix:\sjust\sadd\s"&&(csPtr->toRead\s!=\s0)",\sso\sthat\sit\swill\sfall\nthru\sto\sthe\sbeginning\sof\sthe\sloop,\swhich\sdoes\stest\stoRead.\n\nWe\scan\salso\sunderstand\swhy\sit\swas\s"rare"\sand\s"random":\sthis\sis\sbecause\npeople\soften\suse\s"-size"\sonly\sas\sa\sprogress\sindicator,\sso\sthe\spump\sis\noften\s"re-primed"\sby\sadditional\sdata\son\sthe\schannel\scoming\safter\sthe\ngiven\s-size\sbytes.\sBut\swhat\sabout\sthe\slast\schunk\s?\sI\sbelieve\speople\noften\suse\sa\schannel\swith\sa\sproper\sEOF\s(not\sa\snever-ending\spipe\slike\sin\nMiguel's\sad\shoc\sexample),\swhich\scompletely\shides\sthe\sissue\ssince\sit\nfires\sthe\sreadable\sfileevent\s!\n\nBelow\sis\sa\ssmall\sscript\sshowing\sthe\sbug\swith\sprobability\sone:\sthe\sscript\sblocks\sforever.\nPatched\sversion\scompletes\snormally\safter\sreading\s3\slines\sfrom\sthe\schild\sprocess.\nTest\ssuite\sOK.\n\n-Alex\n\nset\spi\s[open\s"|[info\snameofexecutable]\s2>@\sstderr"\sr+]\nfconfigure\s$pi\s-translation\sbinary\s-buffering\sline\nfconfigure\sstdout\s-translation\sbinary\s-buffering\sline\n\nputs\s$pi\s{\n\s\s\s\sfconfigure\sstdout\s-translation\sbinary\s-buffering\sline\n\s\s\s\sputs\sstderr\sWaiting...\n\s\s\s\safter\s1000\n\s\s\s\sforeach\sx\s{a\sb\sc}\s{\nputs\sstderr\sLooping...\nputs\s$x\nafter\s500\n\s\s\s\s}\n\s\s\s\sputs\sstderr\sNow-sleeping-forever\n\s\s\s\swhile\s{[gets\sstdin\sline]>=0}\s{}\n\s\s\s\sexit\n}\n\nproc\sdone\sargs\s{puts\sstderr\sDONE;exit}\n\nfcopy\s$pi\sstdout\s-size\s6\s-command\sdone\n\nvwait\sforever\n\n
J login ferrieux
J mimetype text/plain
J username ferrieux
K 780533ffffffffffffffffffffffffffffffffff
U ferrieux
Z 44a020292e131210f3fd41d3b15929a1