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

從套接字選擇中跳出

breaking out from socket select(從套接字選擇中跳出)
本文介紹了從套接字選擇中跳出的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我有一個(gè)循環(huán),它基本上每隔幾秒(超時(shí)后)調(diào)用一次:

I have a loop which basically calls this every few seconds (after the timeout):

 while(true){

    if(finished)
       return;

    switch(select(FD_SETSIZE, &readfds, 0, 0, &tv)){
        case SOCKET_ERROR : report bad stuff etc; return;
        default : break;
    }

    // do stuff with the incoming connection
 }

所以基本上每隔幾秒鐘(由電視指定),它就會(huì)重新激活聆聽.

So basically for every few seconds (which is specified by tv), it reactivates the listening.

這是在線程 B(不是主線程)上運(yùn)行的.有時(shí)我想從線程 A(主線程)立即結(jié)束這個(gè)接受器循環(huán),但似乎我必須等到時(shí)間間隔結(jié)束..

This is run on thread B (not a main thread). There are times when I want to end this acceptor loop immediately from thread A (main thread), but seems like I have to wait until the time interval finishes..

有沒有辦法從另一個(gè)線程中斷 select 函數(shù),以便線程 B 可以立即退出?

Is there a way to disrupt the select function from another thread so thread B can quit instantly?

推薦答案

最簡(jiǎn)單的方法大概是使用 pipe(2) 創(chuàng)建一個(gè)管道并將讀取端添加到 readfds.當(dāng)另一個(gè)線程想要中斷 select() 時(shí),只需向它寫入一個(gè)字節(jié),然后再消費(fèi)它.

The easiest way is probably to use pipe(2) to create a pipe and add the read end to readfds. When the other thread wants to interrupt the select() just write a byte to it, then consume it afterward.

這篇關(guān)于從套接字選擇中跳出的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Assertion failed (size.widthgt;0 amp;amp; size.heightgt;0)(斷言失敗(size.width0 amp;amp; size.height0))
Rotate an image in C++ without using OpenCV functions(在 C++ 中旋轉(zhuǎn)圖像而不使用 OpenCV 函數(shù))
OpenCV: process every frame(OpenCV:處理每一幀)
Why can#39;t I open avi video in openCV?(為什么我不能在 openCV 中打開 avi 視頻?)
OpenCV unable to set up SVM Parameters(OpenCV 無法設(shè)置 SVM 參數(shù))
Convert a single color with cvtColor(使用 cvtColor 轉(zhuǎn)換單一顏色)
主站蜘蛛池模板: 九月色婷婷 | 天天做天天干 | 深夜福利在线播放 | av中文网 | 特级特黄aaaa免费看 | 福利小视频在线观看 | 国产91免费 | 亚洲一区在线观看视频 | 久久最新视频 | 欧美激情五月 | 中文字幕不卡视频 | 国产高清视频 | 99国产在线观看 | 成年人一级片 | 国产一区在线播放 | 亚洲激情一区二区 | 日本人の夫妇交换 | 激情六月天 | 巨骚综合 | 欧美一区二区免费 | 国产一区在线播放 | a毛片在线观看 | 中文字幕影院 | 久草综合网 | 久久精品中文字幕 | 日本在线天堂 | 三年中文在线看免费观看 | 激情影院在线观看 | 日韩小视频在线观看 | 欧美人与性动交α欧美精品 | 色呦呦国产精品 | 99视频| 亚洲黄色三级 | 久久久久九九九九 | 日韩精品免费观看 | 欧美日韩四区 | 69福利视频 | 99久久婷婷国产综合精品草原 | 国产日韩在线视频 | 日韩精品免费观看 | 亚洲天堂视频在线观看 |