Epoll模型详解(十二)

2011-12-14 13:02:01 · 作者: · 浏览: 11847
的数据传递出去

         struct user_data *data = NULL;

         while (1)

         {

                   pthread_mutex_lock(&mutex);

                   // 等待到任务队列不为空

                   while (readhead == NULL)

                            pthread_cond_wait(&cond1, &mutex);

                   fd = readhead->fd;

                   // 从任务队列取出一个读任务

                   struct task *tmp = readhead;

                   readhead = readhead->next;

                   delete tmp;

                   pthread_mutex_unlock(&mutex);

                   data = new user_data();

                   data->fd = fd;

                   if ((n = read(fd, data->line, MAXLINE)) < 0)

                   {

                            if (errno == ECONNRESET)

                            {

                                     close(fd);

                            } else