如何对设备执行非阻塞写入?
是否可以进行 write();函数非阻塞而不使用线程?
short buffer[BUFFER_LEN];
int readcount;
while ((readcount = sounds[index].read(buffer, BUFFER_LEN)))
write(audio_device, buffer, readcount * sizeof(short));
声音会播放,但它会阻止程序直到播放完毕。
is it possible to make write(); function non-blocking without using threads?
short buffer[BUFFER_LEN];
int readcount;
while ((readcount = sounds[index].read(buffer, BUFFER_LEN)))
write(audio_device, buffer, readcount * sizeof(short));
The sounds play, but it blocks program until it finished playing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
fcntl
为文件设置O_NONBLOCK
标志可能会起作用,但您需要准备好处理部分写入和EWOULDBLOCK
错误。Using the
fcntl
to set theO_NONBLOCK
flag for the file will probably work, but you need to be prepared to deal with partial writes andEWOULDBLOCK
errors.