Fix the issue "errno:EINTR,while it is suspended by msgrcv."

Fix the issue "errno:EINTR,while it is suspended by msgrcv."


If the calling process is blocked until one of the following conditions occurs:

             1.A message of the desired type is placed in the queue.


             2.The message queue specified by msqid is removed from the system

             3.The calling process receives a signal that is to be caught.

             If the calling process is suspended waiting for a message, the following conditions will cause msgrcv() to return an error and set errno to indicate the error condition.

1.The message queue specified by msqid is removed from the system

2.The calling process receives a signal that is to be caught.


How to fix this issue?

1. Just continue while msgrcv() in while circle.

while(1){

                      if(msgrcv(msg_id,(void *)&event,sizeof(SPRING_EVENT),msg2rec,0) == -1){
                          /*A process waited in msgrcv() was interrupted by a signal.*/
                         if(errno == EINTR){
                             sleep(1);
                             continue;
                        }
                       fprintf(stderr, "msgrcv failed with error: %d\n", errno);
                       exit(EXIT_FAILURE);
                  }

}



2. The other cases. go to maybe good choice.

     come_on:

                      if(msgrcv(msg_id,(void *)&event,sizeof(SPRING_EVENT),msg2rec,0) == -1){
                          /*A process waited in msgrcv() was interrupted by a signal.*/
                         if(errno == EINTR){
                             sleep(1);
                             goto come_on;
                        }
                       fprintf(stderr, "msgrcv failed with error: %d\n", errno);
                       exit(EXIT_FAILURE);
                  }

 



Reference Link:

http://man-wiki.net/index.php/2:msgrcv

http://docs.hp.com/en/36430-90008/ch02s09.html

http://topic.youkuaiyun.com/t/20030323/18/1566458.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值