簡體   English   中英

如何對設備執行非阻塞寫入?

[英]How to perform a non-blocking write to device?

是否可以寫write(); 函數非阻塞而不使用線程?

short buffer[BUFFER_LEN];
int readcount;

while ((readcount = sounds[index].read(buffer, BUFFER_LEN)))
    write(audio_device, buffer, readcount * sizeof(short));

聲音播放,但它阻止程序直到它完成播放。

使用fcntl為文件設置O_NONBLOCK標志可能會有效,但您需要准備好處理部分寫入和EWOULDBLOCK錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM