<i>(windows) socket close: graceful shutdown vs. lingering (eternal TIME_WAIT issue).</i> status still Open with 3 other changes
by
.
D 2020-04-24T18:40:16.147
J icomment Further\sinvestigations\sshows\sthat\sthe\skind\sof\sclose\sdoing\sfrom\sother\sside\s(peer)\sis\salso\svery\simportant\sto\sfulfill\sgraceful\sshutdown\s-\sif\sit\sis\snot\sfollowing\sthe\sstrict\srules\sof\sgraceful\sdisconnect\sprocess,\smany\ssockets\swould\senter\sTIME-WAIT\sstate\s(regardless\sproper\slingering\sset\sfor\sthem).\r\n\r\nFor\sinstance\shere\sis\sthe\sdiff\sillustrating\sbad\s(red)\sand\sgood\s(green)\sserver\saccept\sprocedure\s(in\ssense\sof\sgraceful\sdisconnect),\sif\sa\sclient\speer\sclosing\sit\sproperly\sat\sits\sside\s(with\sWSASendDisconnect,\swait\sfor\sFD_CLOSE,\setc):\r\n<code><pre>\r\nsocket\s-server\s{apply\s{{ch\sargs}\s{\r\n<b\sstyle="color:red">-\s\sclose\s$ch</b>\r\n<b\sstyle="color:green">+\s\schan\sevent\s$ch\sreadable\s[list\sapply\s{{ch}\s{\r\n+\s\s\s\sif\s{[catch\s{string\slength\s[read\s$ch\s1024]}\ss]\s||\s$s\s==\s0}\s{\r\n+\s\s\s\s\s\sclose\s$ch\r\n+\s\s\s\s}\r\n+\s\s}}\s$ch]</b>\r\n}}}\s$port\r\n</pre></code>\r\nTo\ssignal\sthe\sclient\sthat\sit\sis\sdisconnected\simmediately\s(red\scase),\sone\spossibility\swould\sbe\sto\suse\shard\sreset\s(linger\swith\sl_onoff\s=\s1,\sand\sl_linger\s=\s0),\sbut\sthis\sis\spossible\sonly\sif\sno\sdata\swas\sever\ssends,\sso\sexactly\sfor\sthis\scase\s(otherwise\sthis\scan\scause\sa\sloss\sof\ssent\sbut\snot\syet\stransmitted/received\sdata).<br/>\r\nAdditionally\sthe\sTcpThreadActionProc\smakes\sthe\sfix\smore\scomplex,\sbecause\sthe\sclose\sof\schannel\scauses\sthat\sCutChannel\sis\sinvoked\s(without\spossibility\sto\sdistinguish\sclose\sand\sdetach)\sbefore\sTcpCloseProc\swill\sbe\sexecuted,\sso\sit\sremoves\sthe\ssocket\sfrom\sco-thread\s("windowed"\shandler,\sthat\shandles\sthis\ssocket\snormally).
J login sebres
J mimetype text/x-fossil-wiki
K b6d0d8cc2c82dbb366d1fb3f32afd2a027a41135
U sebres
Z fca2170f2ee46da46ee5bc56092cbd41