久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

      <legend id='7c2al'><style id='7c2al'><dir id='7c2al'><q id='7c2al'></q></dir></style></legend>
    1. <tfoot id='7c2al'></tfoot>
        <bdo id='7c2al'></bdo><ul id='7c2al'></ul>

      <i id='7c2al'><tr id='7c2al'><dt id='7c2al'><q id='7c2al'><span id='7c2al'><b id='7c2al'><form id='7c2al'><ins id='7c2al'></ins><ul id='7c2al'></ul><sub id='7c2al'></sub></form><legend id='7c2al'></legend><bdo id='7c2al'><pre id='7c2al'><center id='7c2al'></center></pre></bdo></b><th id='7c2al'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='7c2al'><tfoot id='7c2al'></tfoot><dl id='7c2al'><fieldset id='7c2al'></fieldset></dl></div>
    2. <small id='7c2al'></small><noframes id='7c2al'>

        Win32 - 從標(biāo)準(zhǔn)輸入讀取超時(shí)

        Win32 - read from stdin with timeout(Win32 - 從標(biāo)準(zhǔn)輸入讀取超時(shí))
          <legend id='yQird'><style id='yQird'><dir id='yQird'><q id='yQird'></q></dir></style></legend>
          1. <i id='yQird'><tr id='yQird'><dt id='yQird'><q id='yQird'><span id='yQird'><b id='yQird'><form id='yQird'><ins id='yQird'></ins><ul id='yQird'></ul><sub id='yQird'></sub></form><legend id='yQird'></legend><bdo id='yQird'><pre id='yQird'><center id='yQird'></center></pre></bdo></b><th id='yQird'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='yQird'><tfoot id='yQird'></tfoot><dl id='yQird'><fieldset id='yQird'></fieldset></dl></div>

            • <bdo id='yQird'></bdo><ul id='yQird'></ul>
                <tbody id='yQird'></tbody>

              <small id='yQird'></small><noframes id='yQird'>

                • <tfoot id='yQird'></tfoot>

                  本文介紹了Win32 - 從標(biāo)準(zhǔn)輸入讀取超時(shí)的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  我正在嘗試做一些我認(rèn)為應(yīng)該很簡(jiǎn)單的事情:從標(biāo)準(zhǔn)輸入進(jìn)行阻塞讀取,但如果沒(méi)有數(shù)據(jù)可用,則在指定的時(shí)間間隔后超時(shí).

                  I'm trying to do something which I think should be simple: do a blocking read from standard input, but timing out after a specified interval if no data is available.

                  在 Unix 世界中,使用 select() 會(huì)很簡(jiǎn)單,但這在 Windows 中不起作用,因?yàn)?stdin 不是套接字.在不創(chuàng)建額外線程等的情況下,下一個(gè)最簡(jiǎn)單的選擇是什么?

                  In the Unix world this would be simple with select() but that doesn't work in Windows because stdin isn't a socket. What's the next simplest option without creating extra threads etc?

                  我使用的是面向 Win32 環(huán)境的 Visual C++.

                  I'm using visual C++ targeting a Win32 environment.

                  到目前為止我已經(jīng)嘗試過(guò):

                  so far I have tried:

                  1. 使用 select(如果輸入不是套接字則不起作用)

                  1. using select (doesn't work if the input is not a socket)

                  使用WaitForSingleObject(GetStdHandle(STD_INPUT_HANDLE)).- 雷米的第一個(gè)建議.如果標(biāo)準(zhǔn)輸入是控制臺(tái),這似乎總是在您調(diào)用它時(shí)立即返回(其他人報(bào)告了同樣的問(wèn)題)

                  using WaitForSingleObject(GetStdHandle(STD_INPUT_HANDLE)). - Remy's first suggestion. This always seems to return immediately when you call it if the standard input is a console (others have reported the same problem)

                  使用重疊 IO 并執(zhí)行 WaitForSingleObject(Remy 的第三個(gè)建議).在這種情況下,當(dāng)輸入來(lái)自控制臺(tái)時(shí),讀取似乎總是阻塞 - 似乎 stdin 不支持異步 I/O.

                  using overlapped IO and doing a WaitForSingleObject (Remy's third suggestion). In this case the read always seems to block when the input is coming from a console - it seems that stdin does not support asynchronous I/O.

                  目前我在想我唯一剩下的選擇是創(chuàng)建一個(gè)線程,該線程將執(zhí)行阻塞讀取,然后發(fā)出一個(gè)事件信號(hào),然后有另一個(gè)線程等待該事件超時(shí).

                  At the moment I'm thinking my only remaining option is to create a thread which will do a blocking read and then signal an event, and then have another thread which waits for the event with a timeout.

                  推薦答案

                  我不得不解決一個(gè)類(lèi)似的問(wèn)題.在 Windows 上,它不像 Linux 那樣容易或明顯.然而,這是可能的.訣竅是 Windows 將控制臺(tái)事件放在控制臺(tái)輸入事件隊(duì)列中.您必須過(guò)濾掉您不關(guān)心的事件,只處理您真正關(guān)心的事件(例如按鍵).

                  I had to solve a similar problem. On Windows it is not as easy or obvious as Linux. It is, however, possible. The trick is that Windows places console events in the console input event queue. You've got to filter out the events you don't care about and only process those events you do care about (like key presses).

                  進(jìn)一步閱讀:請(qǐng)參閱 Win32 控制臺(tái)文檔

                  以下是一些基于套接字和標(biāo)準(zhǔn)輸入多路復(fù)用器的主要調(diào)試示例代碼:

                  Here is some mostly-debugged sample code based on a socket and stdin multiplexer I was working on:

                  void ProcessStdin(void)
                  {
                      INPUT_RECORD record;
                      DWORD numRead;
                      if(!ReadConsoleInput(GetStdHandle(STD_INPUT_HANDLE), &record, 1, &numRead)) {
                          // hmm handle this error somehow...
                          return;
                      }
                  
                      if(record.EventType != KEY_EVENT) {
                          // don't care about other console events
                          return;
                      }
                  
                      if(!record.Event.KeyEvent.bKeyDown) {
                          // really only care about keydown
                          return;
                      }
                  
                      // if you're setup for ASCII, process this:
                      //record.Event.KeyEvent.uChar.AsciiChar
                  
                  } // end ProcessStdin
                  
                  int main(char argc, char* argv[])
                  {
                      HANDLE eventHandles[] = {
                          GetStdHandle(STD_INPUT_HANDLE)
                          // ... add more handles and/or sockets here
                          };
                  
                      DWORD result = WSAWaitForMultipleEvents(sizeof(eventHandles)/sizeof(eventHandle[0]), 
                          &eventHandles[0], 
                          FALSE, 
                          1000, 
                          TRUE
                          );
                  
                      switch(result) {
                          case WSA_WAIT_TIMEOUT: // no I/O going on right now
                              break;
                  
                          case WSA_WAIT_EVENT_0 + 0: // stdin at array index 0
                              ProcessStdin();
                              break;
                  
                          case WSA_WAIT_EVENT_0 + 1: // handle/socket at array index 1
                              break;
                  
                          case WSA_WAIT_EVENT_0 + 2: // ... and so on
                              break;
                  
                          default: // handle the other possible conditions
                              break;
                      } // end switch result
                  }
                  

                  這篇關(guān)于Win32 - 從標(biāo)準(zhǔn)輸入讀取超時(shí)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  In what ways do C++ exceptions slow down code when there are no exceptions thown?(當(dāng)沒(méi)有異常時(shí),C++ 異常會(huì)以何種方式減慢代碼速度?)
                  Why catch an exception as reference-to-const?(為什么要捕獲異常作為對(duì) const 的引用?)
                  When and how should I use exception handling?(我應(yīng)該何時(shí)以及如何使用異常處理?)
                  Scope of exception object in C++(C++中異常對(duì)象的范圍)
                  Catching exceptions from a constructor#39;s initializer list(從構(gòu)造函數(shù)的初始化列表中捕獲異常)
                  Difference between C++03 throw() specifier C++11 noexcept(C++03 throw() 說(shuō)明符 C++11 noexcept 之間的區(qū)別)
                    <tbody id='qFdGi'></tbody>

                • <small id='qFdGi'></small><noframes id='qFdGi'>

                  <i id='qFdGi'><tr id='qFdGi'><dt id='qFdGi'><q id='qFdGi'><span id='qFdGi'><b id='qFdGi'><form id='qFdGi'><ins id='qFdGi'></ins><ul id='qFdGi'></ul><sub id='qFdGi'></sub></form><legend id='qFdGi'></legend><bdo id='qFdGi'><pre id='qFdGi'><center id='qFdGi'></center></pre></bdo></b><th id='qFdGi'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='qFdGi'><tfoot id='qFdGi'></tfoot><dl id='qFdGi'><fieldset id='qFdGi'></fieldset></dl></div>
                  <tfoot id='qFdGi'></tfoot>

                      <bdo id='qFdGi'></bdo><ul id='qFdGi'></ul>
                        <legend id='qFdGi'><style id='qFdGi'><dir id='qFdGi'><q id='qFdGi'></q></dir></style></legend>

                          1. 主站蜘蛛池模板: 日韩久久精品视频 | 日韩免费视频一区二区 | 一区二区三区国产视频 | 亚洲欧美日韩精品久久亚洲区 | 午夜欧美一区二区三区在线播放 | 国产一区 在线视频 | 成人福利网 | caoporon| 欧美一区二区在线播放 | 精品国产欧美一区二区三区不卡 | 久久69精品久久久久久久电影好 | 亚洲欧美日韩精品久久亚洲区 | 91视视频在线观看入口直接观看 | 成人福利视频网站 | 麻豆av免费观看 | 美女在线观看av | 欧洲毛片 | 精品二区视频 | 久久精品欧美一区二区三区不卡 | 国内av在线 | 一级aaaaaa毛片免费同男同女 | 中文在线a在线 | 成人国产综合 | 欧美激情久久久 | 国产免费一区 | 久久久精品黄色 | 亚洲乱码一区二区三区在线观看 | 老司机精品福利视频 | 欧美成人精品二区三区99精品 | 久久国产欧美日韩精品 | 99re | 国产成人精品视频在线观看 | 91新视频 | 日韩中文字幕 | 成人精品毛片国产亚洲av十九禁 | 欧美日韩国产精品 | 中文字幕av网 | 伊色综合久久之综合久久 | 欧美午夜一区 | 亚洲成人三级 | 毛片入口 |