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

来源:互联网 发布:淘宝买东西扣银行卡吗 编辑:程序博客网 时间:2024/06/06 06:15
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.csdn.net/t/20030323/18/1566458.html
原创粉丝点击