void parse(int cfd) { char buf[1024]; char buf1[64]; int ret; int b; Node* t; Node* s; struct package p; ret = read(cfd, &p.head, sizeof(p.head)); if(ret <=0){ printf("cfd=%d close!\n",cfd); removelist(cfd); close(cfd); ev.data.fd = cfd; epoll_ctl(eh,EPOLL_CTL_DEL,ev.data.fd,&ev); } strcpy(buf1,p.head.type); printf("buf1=%s\n",buf1); if(buf1[0] == 'g') { pool_add_work(thread,(void*)cfd); }else if(buf1[0] == 'f'){ // printf("sddsddsd\n"); pool_add_work(regiser,(void*)cfd); }else if(buf1[0] == 'h'){ printf("oooooooooooooook\n"); pool_add_work(show_list,(void*)cfd); }else{ t = search_b(buf1); if(t != NULL) { ret = read(cfd,buf,sizeof(buf)); printf("buf=%s\n",buf); if(ret <=0){ close(cfd); printf("close cfd+%d\n",cfd); //return argv; } s = search_cfd(cfd); strcpy(p.head.type , s->name); printf("p.head.type=%s\n",p.head.type); p.head.version = 1; p.head.length = strlen(buf); //cfd = t->fcd; printf("t->fcd=%d\n",t->fcd); write(t->fcd,&p.head,sizeof(p.head)); write(t->fcd,buf,p.head.length); memset(buf,0,1024); } } }
int main(void){ pool_t pool; struct timeb st1, st2; long long t1,t2; ftime(&st1); pool_init(&pool); // int num[10000]; for(int i = 0; i < 10000; ++i){ // num[i] = i; pool_add_work(&pool, myprintf, &i); //由于传入的是指针,例程函数溯源找到了i的本源导致了错误 } // sleep(1); // printf("\n"); // for(int j = 0; j < 20; ++j){ // printf("%d ", *(int *)(pool.work_queue[j].arg)); // } // pthread_cond_broadcast(&pool.pool_ready); // pthread_join(pool.workers[0].id, NULL); while(pool.cur_queue_size != 0); /* for(int i = 0; i < 10000; ++i){ printf("%d\t", i); } */ ftime(&st2); t1 = (long long)st1.time*1000 + st1.millitm; t2 = (long long)st2.time*1000 + st2.millitm; long long i = t2 - t1; printf("%lld", i); sleep(1); // fflush(stdout); }