Skip to content
Tcl Source Code Artifact [b2b56a12eb]
Login

Artifact [b2b56a12eb]

Artifact b2b56a12eb1f367b168b8079f8805570eaaa6237:

Ticket change [b2b56a12eb] - New ticket [3401422fffffffff|3401422fff] <i>socket -async: channel vs. socket blocking/non-blocking mode</i>. by foxcruiser on 2011-08-31 09:42:32.
D 2011-08-31T09:42:32
J assignee andreas_kupries
J cmimetype text/plain
J comment uname\s-v\s\n->\sDarwin\sKernel\sVersion\s10.8.0:\sTue\sJun\s\s7\s16:33:36\sPDT\s2011;\sroot:xnu-1504.15.3~1/RELEASE_I386\n\nyesterday\sI\shad\sa\slegacy\sscript,\swhich\ssets\sup\sand\s[read]s\sfrom\san\sasync\sclient-side\ssocket\sin\schannel\snon-blocking\smode,\sevaluated\sby\s8.6b2\s(fossil\stag\score-8-6-b2);\sthe\sscript\shas\sbeen\srunning\swithout\sissues\sstarting\sfrom\s8.3+\sthrough\s8.5.10,\sto\smy\sknowledge.\sI\sfound\sa\sslight\sbehavioural\sshift\swhich\sleft\sme\spuzzled\sfor\ssome\stime.\sthe\sscript\sdid\sthe\sfollowing\sat\sthe\sclient\sside:\n\nset\sclient\s[::socket\s-async\slocalhost\s9000]\n::fconfigure\s$client\s-encoding\sbinary\s-translation\sbinary\s-blocking\s0;\s#\sthe\sscripts\swants\sthe\schannel\sand\sthe\ssock\sto\sbe\sin\snon-blocking\smode!\n::fileevent\s$client\swritable\s[list\swrite]\n\nIn\sthe\s[write]\shandler,\sthe\sscript\s[puts]\ssth\sto\sits\speer,\sthen\swaits\sfor\sa\s[fileevent\sreadable]\sto\sreceive\sthe\sresponse\sby\s[read]\n\nread\s$client\n\nthis\s[read],\showever,\sblocked\s...\sseemingly\sobvious,\sbecause\sit\swas\sunconditional\s(numChars\s...),\sto\sbegin\swith,\sbut\sthe\sscript\sexpected\sit\sto\sbe\snon-blocking\s(channel\s&\ssock).\sA\s[fconfigure\s$client\s-blocking]\sright\sbefore\sthe\s[read]\ssaid\s0\s(non-blocking\schannel).\sstill,\sit\swas\sblocking.\swhen\sdoing\ssome\sstrace'ing,\sI\sfound\sthat\sthe\ssocket\sto\s[read]\sfrom\s(recv())\sdid\snot\shave\sthe\sO_NONBLOCK\sflag\sset,\safter\sall,\sthough\srequested\sabove?!\n\ni\sthen\shad\sa\slook\sat\sthe\scode\sbase\s(tclUnixSock.c)\sand\srecognized\sthat\sa\slot\shas\schanged\sunder\sthe\shood\ssince\s8.5(.10);\swhen\sskimming\sover\sthe\scode,\sI\sfound\schanges\sfor\shandling\sthe\sasync\sclient\ssocks,\susing\sa\sC-level\sfileevent\shandler:\sTcpAsyncCallback().\n\nWhen\sre-entering\sCreateClientSocket()\sby\sprocessing\sthe\scallback,\sthe\sunix\ssock\sis\spushed\sinto\sblocking\smode\sexplicitly:\s\s\s\s\s\s\s\s\sTclUnixSetBlockingMode(state->fds.fd,\sTCL_MODE_BLOCKING);\sThis\sexplained\sat\sleast,\swhy\s[read]\sabove\swas\sseeing\sa\sblocking\ssock,\swhile\sthe\schannel\swas\sreported\sas\snon-blocking\sby\s[fconfigure].\n\nWhy\sis\sthis\sTclUnixSetBlockingMode(state->fds.fd,\sTCL_MODE_BLOCKING)\sneeded?\sI\sguess,\sit\smade\sit\sinto\sthe\scode\sbecause\sof\sBug\s4388:\nhttp://sourceforge.net/tracker/index.php?func=detail&aid=219061&group_id=10894&atid=110894\n\n...\sthe\sBug-4388-patch\sintended\sto\skeep\schannel\sand\ssock\s"in\ssync",\sright\s(when\sintrospected\sthrough\s[fconfigure]?\nbut\snow\sthings\shave\schanged,\sby\sintroducing\sthe\sTcpAsyncCallback():\n\n1)\sAs\sfor\sBug\s4388,\safter\sa\s[socket\s-async],\s[fconfigure\s$client\s-blocking]\sreturns\s"1"\swhile\sO_NONBLOCK\s\sis\sset\s...\sis\sthis\sintended?\n2)\sAs\sfor\smy\sscript:\sreqesting\sthe\snon-blocking\smode\sright\safter\san\s[socket\s-async]\s(as\sshown\sabove)\swill\sbe\soverruled\sby\sTcpAsyncCallback();\sthe\sonly\s"safe"\splace\sto\sdo\sso\sis\sin\sthe\sfirst\sscript-level\swritable\shandler\sprocessed\safter\sTcpAsyncCallback(),\scorrect?\sIf\sso,\sthis\sshould\sbe\sdocumented\sprominently:\sDon't\sexpected\s[fconfigure]\sto\sreport\sor\sset\sa\schannels\sstate\sbefore\sthe\sfirst\swritable\sevent\shas\sbeen\ssignalled!\n\nSo,\show\sshould\s[fconfigure]\sand\ssock\sconfigurations\sbe\skept\s"in\ssync"\s(Bug\s4388\sfor\sblocking\smode\srequest\sand\smy\scase\shaving\srequest\snon-blocking\sbefore\sTclAsyncCallback()\swas\sfired).\sWhat\sare\sthe\sintended\ssemantics\sfor\srequesting\snon-blocking\smode\sfor\sa\schannel/sock\spair\swhen\susing\s[socket\s-async]?
J foundin obsolete:\s8.6b2
J is_private 0
J priority 5\sMedium
J resolution None
J status Open
J submitter foxcruiser
J subsystem 27.\sChannel\sTypes
J title socket\s-async:\schannel\svs.\ssocket\sblocking/non-blocking\smode
J type Bug
K 3401422fffffffffffffffffffffffffffffffff
U foxcruiser
Z c3c6198ffaa00e6b97d91118ddb63798