原创 Issue "errno:EINTR,while it calls msgrcv."

2009-11-24 23:57 3636 7 7 分类: 软件与OS
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

文章评论0条评论)

登录后参与讨论
我要评论
0
7
关闭 站长推荐上一条 /2 下一条