- 论坛徽章:
- 0
|
void *GetBuf(void* p)
{
pthread_detach(pthread_self());
....................
printf("listen successful , sockfd is %d \n", sockfd)
if(-1 == (iListenfd = accept(sockfd, (struct sockaddr *)NULL, NULL)))
{
printf ("accept failed : %s \n", strerror(errno));
exit(1);
}
printf("accept successful \n" ;
..........................
}
int main()
{
pthread_t pthID;
//GetBuf((void *) );
pthread_create (&pthID, NULL, &GetBuf, (void *)NULL);
}
测试时主函数里就这一个线程,总是在调用accept后就自动退出,没有打印出错误原因。只打印出前一句listen调用成功,sockfd为一非负值。
如果不用线程,直接调用GetBuf,则accept成功。 |
|