- 论坛徽章:
- 0
|
线程之间能不能管道啊!
还有我的线程开了怎么没反映啊,线程里的好象都没做啊
我的主程序执行到开线程的地方在下面就没了怎么回事呢????
fd全局的
mask,sdmax,SOCKMAX都是全局的
void *Recvdata(void *)
{
int status = 0;
int nbytes = 0;
char buffer[BUF_SIZE] ="0";
char str[BUF_SIZE] = "0";
char pipedata[2*BUF_SIZE]= "0";
struct fd_set rmask;
close(fd[0]);
for ( ; ; )
{
rmask = mask;
status = select(sdmax + 1, &rmask, ZERO, ZERO, NULL);
if (status >; 0)
{
for(int i = 0; i < SOCKMAX; i++)
{
if (FD_ISSET(sd, &rmask))
{
bzero(pipedata,2*BUF_SIZE);
bzero(buffer,BUF_SIZE);
nbytes = read(sd, buffer, BUF_SIZE);
bzero(str,BUF_SIZE);
getNodeId(sd,str);
if (nbytes >; 0)
{
strncpy(pipedata, buffer, BUF_SIZE);
strncat(pipedata,str,BUF_SIZE);
printf("node:%s\n",pipedata);
write(fd[1], pipedata, 2*BUF_SIZE);
}
if(nbytes <= 0)
{
close(sd);
if (sd >;= sdmax)
sdmax = sd[i-1];
SOCKMAX--;
}//end if close
}//end if FD_ISSET
}//end for
if (status < 0)break;
}
}
}
pthread_create(&threadrecv,PTHREAD_CREATE_DETACHED,Recvdata,NULL); |
|