如何在vxworks或linux上取消被阻止的read/recvfrom系统调用 [英] How can I cancel a blocked read/recvfrom system call on vxworks or linux

查看:229
本文介绍了如何在vxworks或linux上取消被阻止的read/recvfrom系统调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任务I 中:

...

while (1)
{
  if (running == false)
  break;
  ret = read(fd, buf, size); /* Or: ret = recvfrom(sock, buf, size, 0, NULL, NULL); */
  ...
 }

任务II 中:

...
running = true;
/* ioctl(fd, FIOCANCEL, 0); */
close(fd);   /* Or: close(sock);*/

任务II 中的操作应取消被阻止的任务I

what should do in task II to cancel the blocked task I,

vxworks 中,有一个功能ioctl(fd, FIOCANCEL, 0)取消被阻止的读取或写入,但是它无法工作.可能是因为驱动程序不支持"FIOCANCEL" .

In vxworks, there is a function, ioctl(fd, FIOCANCEL, 0) to cancel a blocked read or write but it can not work. Probably because the driver can not support "FIOCANCEL".

如何在vxworks和linux中编写任务II?还是有其他方法可以完成我的任务?

how to write task II in vxworks and linux? or are there any other way to do my task?

推荐答案

在Linux上,不可能取消read/recvfrom调用.您不能使用相同的API编写这些任务.在Linux上,您可以使用epoll和O_NONBLOCK来创建取消读取/接收的语义.

Cancelling a read/recvfrom call is impossible on linux. You cannot write these tasks using the same API. On Linux you can use epoll and O_NONBLOCK to create the semantics of canceling a read/recvfrom.

对于Linux和vxworks,使用相同的代码来做到这一点是不可能.

It is impossible to do this using the same code for both linux and vxworks.

这篇关于如何在vxworks或linux上取消被阻止的read/recvfrom系统调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆