sigset调用函数返回问题。

空的 2011-07-07 09:53:51
求解:
int flag=0;

main()
{
sigset(SIGALRM, msg_to);
alarm(60);

ret=msqRcv(..........);
if(ret<0 && flag==1)
{
打印。。;
退出或怎么的;
}
....;
}
void msg_to
{
打印啥的;
flag=1;
}

怎么改才能使语句执行到if,而不是一直在那等接受socketid的内容?
...全文
370 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
至善者善之敌 2011-07-07
  • 打赏
  • 举报
回复
socketid ?套接字,你的程序太伪了。。。
伪的。。。都看不明白了
呔妖怪来嘛 2011-07-07
  • 打赏
  • 举报
回复
sigset是什么
至善者善之敌 2011-07-07
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 lenovo_ 的回复:]
阻塞的read 你可以设置套接字选项 setsockopt,设置多长时间没有接收到数据就返回

int setsockopt(int socket, int level, int option_name,
const void *option_value, socklen_t option_len);


SO_RCVTIMEO
Sets the timeout v……
[/Quote]

经常这么用,是个折中的方案
LENOVO_ 2011-07-07
  • 打赏
  • 举报
回复
阻塞的read 你可以设置套接字选项 setsockopt,设置多长时间没有接收到数据就返回

int setsockopt(int socket, int level, int option_name,
const void *option_value, socklen_t option_len);


SO_RCVTIMEO
Sets the timeout value that specifies the maximum amount of time an input function waits until it completes. It accepts a timeval structure with the number of seconds and microseconds specifying the limit on how long to wait for an input operation to complete. If a receive operation has blocked for this much time without receiving additional data, it shall return with a partial count or errno set to [EAGAIN] or [EWOULDBLOCK] if no data is received. The default for this option is zero, which indicates that a receive operation shall not time out. This option takes a timeval structure. Note that not all implementations allow this option to be set.
qq120848369 2011-07-07
  • 打赏
  • 举报
回复
可以用select取代你的阻塞read.
justkk 2011-07-07
  • 打赏
  • 举报
回复
signal(SIGALRM, msg_to)
空的 2011-07-07
  • 打赏
  • 举报
回复
就是说在socket接受时,一直等不到信息发过来,就一直read ,所以设置了一个alarm,
然后sigset(SIGALRM, msg_to),希望可以通过这样结束read或继续循环。。

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧