{"id":6324,"date":"2022-12-20T18:58:09","date_gmt":"2022-12-20T21:58:09","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/close-mann\/"},"modified":"2022-12-20T18:58:09","modified_gmt":"2022-12-20T21:58:09","slug":"close-mann","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/close-mann\/","title":{"rendered":"close (mann)"},"content":{"rendered":"<h1 align=\"center\">close<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#EXAMPLE\">EXAMPLE<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#KEYWORDS\">KEYWORDS<\/a> <\/p>\n<hr>\n<p>______________________________________________________________________________<\/p>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">close \u2212 Close an open channel<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>close<\/b> <i>channelId<\/i> ?r(ead)|w(rite)? ______________________________________________________________________________<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Closes or half-closes the channel given by <i>channelId<\/i>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>ChannelId<\/i> must be an identifier for an open channel such as a Tcl standard channel (<b>stdin<\/b>, <b>stdout<\/b>, or <b>stderr<\/b>), the return value from an invocation of <b>open<\/b> or <b>socket<\/b>, or the result of a channel creation command provided by a Tcl extension.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The single-argument form is a simple \u201cfull-close\u201d: all buffered output is flushed to the channel\u2019s output device, any buffered input is discarded, the underlying file or device is closed, and <i>channelId<\/i> becomes unavailable for use.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If the channel is blocking, the command does not return until all output is flushed. If the channel is nonblocking and there is unflushed output, the channel remains open and the command returns immediately; output will be flushed in the background and the channel will be closed when all the flushing is complete.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If <i>channelId<\/i> is a blocking channel for a command pipeline then <b>close<\/b> waits for the child processes to complete.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If the channel is shared between interpreters, then <b>close<\/b> makes <i>channelId<\/i> unavailable in the invoking interpreter but has no other effect until all of the sharing interpreters have closed the channel. When the last interpreter in which the channel is registered invokes <b>close<\/b>, the cleanup actions described above occur. See the <b>interp<\/b> command for a description of channel sharing.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Channels are automatically closed when an interpreter is destroyed and when the process exits. From 8.6 on (TIP#398), nonblocking channels <big>\u2502<\/big> are no longer switched to blocking mode when exiting; this guarantees a <big>\u2502<\/big> timely exit even when the peer or a communication channel is stalled. <big>\u2502<\/big> To ensure proper flushing of stalled nonblocking channels on exit, one <big>\u2502<\/big> must now either (a) actively switch them back to blocking or (b) use <big>\u2502<\/big> the environment variable TCL_FLUSH_NONBLOCKING_ON_EXIT, which when set <big>\u2502<\/big> and not equal to &#8220;0&#8221; restores the previous behavior.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The command returns an empty string, and may generate an error if an error occurs while flushing output. If a command in a command pipeline created with <b>open<\/b> returns an error, <b>close<\/b> generates an error (similar to the <b>exec<\/b> command.)<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The two-argument form is a \u201chalf-close\u201d: given a bidirectional channel <big>\u2502<\/big> like a socket or command pipeline and a (possibly abbreviated) <big>\u2502<\/big> direction, it closes only the sub-stream going in that direction. This <big>\u2502<\/big> means a shutdown() on a socket, and a close() of one end of a pipe for <big>\u2502<\/big> a command pipeline. Then, the Tcl-level channel data structure is <big>\u2502<\/big> either kept or freed depending on whether the other direction is still <big>\u2502<\/big> open. <big>\u2502<\/big><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">A single-argument close on an already half-closed bidirectional channel <big>\u2502<\/big> is defined to just \u201cfinish the job\u201d. A half-close on an already closed <big>\u2502<\/big> half, or on a wrong-sided unidirectional channel, raises an error. <big>\u2502<\/big><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">In the case of a command pipeline, the child-reaping duty falls upon <big>\u2502<\/big> the shoulders of the last close or half-close, which is thus allowed to <big>\u2502<\/big> report an abnormal exit error. <big>\u2502<\/big><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Currently only sockets and command pipelines support half-close. A <big>\u2502<\/big> future extension will allow reflected and stacked channels to do so.<\/p>\n<h2>EXAMPLE <a name=\"EXAMPLE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This illustrates how you can use Tcl to ensure that files get closed even when errors happen by combining <b>catch<\/b>, <b>close<\/b> and <b>return<\/b>:<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">proc withOpenFile {filename channelVar script} { <br \/> upvar 1 $channelVar chan <br \/> set chan [open $filename] <br \/> catch { <br \/> uplevel 1 $script <br \/> } result options <b><br \/> close<\/b> $chan <br \/> return -options $options $result <br \/> }<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">file(n), open(n), socket(n), eof(n), Tcl_StandardChannels(3)<\/p>\n<h2>KEYWORDS <a name=\"KEYWORDS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">blocking, channel, close, nonblocking, half-close<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  close \u2212 Close an open channel <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3783,1],"tags":[2083,2635],"class_list":["post-6324","post","type-post","status-publish","format-standard","hentry","category-n-comandos-tcl-tk","category-sin-categoria","tag-close","tag-mann"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6324","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=6324"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6324\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=6324"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=6324"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=6324"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}