{"id":11753,"date":"2011-01-14T07:00:00","date_gmt":"2011-01-14T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2011\/01\/14\/whats-the-difference-between-an-asynchronous-pipe_wait-pipe-and-a-pipe_nowait-pipe\/"},"modified":"2011-01-14T07:00:00","modified_gmt":"2011-01-14T07:00:00","slug":"whats-the-difference-between-an-asynchronous-pipe_wait-pipe-and-a-pipe_nowait-pipe","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20110114-00\/?p=11753","title":{"rendered":"What&#039;s the difference between an asynchronous PIPE_WAIT pipe and a PIPE_NOWAIT pipe?"},"content":{"rendered":"<p>When you operate on named pipes, you have a choice of opening them in <code>PIPE_WAIT<\/code> mode or <code>PIPE_NOWAIT<\/code> mode. When you read from a <code>PIPE_WAIT<\/code> pipe, the read blocks until data becomes available in the pipe. When you read from a <code>PIPE_NOWAIT<\/code> pipe, then the read completes immediately even if there is no data in the pipe. But how is this different from a <code>PIPE_WAIT<\/code> pipe opened in asynchronous mode by passing <code>FILE_FLAG_OVERLAPPED<\/code>?\n The difference is in when the I\/O is deemed to have completed.\n When you issue an overlapped read against a <code>PIPE_WAIT<\/code> pipe, the call to <code>Read&shy;File<\/code> returns immediately, but the completion actions do not occur until  there is data available in the pipe. (<i>Completion actions<\/i> are things like setting the event, running the completion routine, or queueing a completion to an I\/O completion port.) On the other hand, when you issue a read against a <code>PIPE_NOWAIT<\/code> pipe, the call to <code>Read&shy;File<\/code> returns immediately <i>with completion<\/i>&mdash;if the pipe is empty, the read completes with a read of zero bytes and the error <code>ERROR_NO_DATA<\/code>.\n Here&#8217;s a timeline, for people who prefer tables.<\/p>\n<table border=\"1\" style=\"border-collapse: collapse\" cellpadding=\"3\">\n<tbody>\n<tr>\n<th>Event     <\/th>\n<th valign=\"baseline\">Asynchronous <code>PIPE_WAIT<\/code><\/th>\n<th valign=\"baseline\"><code>PIPE_NOWAIT<\/code><\/th>\n<\/tr>\n<tr>\n<td colspan=\"3\" align=\"center\">pipe initially empty<\/td>\n<\/tr>\n<tr>\n<td valign=\"baseline\">ReadFile<\/td>\n<td valign=\"baseline\">Returns immediately with <code>ERROR_IO_PENDING<\/code><\/td>\n<td valign=\"baseline\">Returns immediately with <code>ERROR_NO_DATA<\/code><br \/>         I\/O completes with 0 bytes<\/td>\n<\/tr>\n<tr>\n<td colspan=\"3\" align=\"center\">time passes<\/td>\n<\/tr>\n<tr>\n<td valign=\"baseline\">Data available<\/td>\n<td valign=\"baseline\">I\/O completes with <i>n<\/i>&nbsp;&gt;&nbsp;0 bytes<\/td>\n<td valign=\"baseline\"><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p> If you use the <code>PIPE_NOWAIT<\/code> flag, then the only way to know whether there is data is to poll for it. There is no way to be notified when data becomes available.<\/p>\n<p> As the documentation notes, <code>PIPE_NOWAIT<\/code> remains solely for compatibility with LAN Manager&nbsp;2.0. Since the only way to use pipes created as <code>PIPE_NOWAIT<\/code> is to poll them, this is obviously not a recommended model for a multitasking operating system. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>When you operate on named pipes, you have a choice of opening them in PIPE_WAIT mode or PIPE_NOWAIT mode. When you read from a PIPE_WAIT pipe, the read blocks until data becomes available in the pipe. When you read from a PIPE_NOWAIT pipe, then the read completes immediately even if there is no data in [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-11753","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>When you operate on named pipes, you have a choice of opening them in PIPE_WAIT mode or PIPE_NOWAIT mode. When you read from a PIPE_WAIT pipe, the read blocks until data becomes available in the pipe. When you read from a PIPE_NOWAIT pipe, then the read completes immediately even if there is no data in [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/11753","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=11753"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/11753\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=11753"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=11753"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=11753"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}