while (1)
{
int n,i,iret;
n = -1;
printf("------------------sock_fd is %d\n",sock_fd);
if(sock_fd<0){
sock_fd=client_sock(ser_port,ser_ip);
printf("after client , sock_fd is %d\n",sock_fd);
if(sock_fd<0){
sleep(2);
continue;
}
}
memset(tmp_buf,0,sizeof(tmp_buf));
if(mark ==1)
{
printf("test n is %d\n",n);
printf("++++++++++++++++sock_fd is %d\n",sock_fd);
n = read(sock_fd,tmp_buf,sizeof(tmp_buf));
printf("after read, n is %d",n);
}
else if(mark ==0){
printf("mark not 1\n");
break;
}
printf("after mark , n is %d",n);
...
}
程序输出的结果是:
------------------sock_fd is -1
sock_fd is -1
after client , sock_fd is 7
test n is -1
++++++++++++++++sock_fd is 7
------------------sock_fd is -1
程序结果是重复这样
------------------sock_fd is -1
sock_fd is -1
after client , sock_fd is 100
test n is -1
++++++++++++++++sock_fd is 100
------------------sock_fd is -1
sock_fd is -1
after client , sock_fd is 101
test n is -1
++++++++++++++++sock_fd is 101
------------------sock_fd is -1
sock_fd is -1
after client , sock_fd is 102
test n is -1
++++++++++++++++sock_fd is 102
------------------sock_fd is -1
sock_fd is -1
after client , sock_fd is 103
test n is -1
++++++++++++++++sock_fd is 103
------------------sock_fd is -1
sock_fd is -1
after client , sock_fd is 104
我有两个循环
while(1){
printf("in while 1\n");
int iDataType=0;
int iHead =1;
int mark =1;
while (1)
{
int n,i,iret;
n = -1;
printf("------------------sock_fd is %d\n",sock_fd);
if(sock_fd<0){
printf("sock_fd is %d\n",sock_fd);
sock_fd=client_sock(ser_port,ser_ip);
printf("after client , sock_fd is %d\n",sock_fd);
if(sock_fd<0){
sleep(2);
continue;
}
}
memset(tmp_buf,0,sizeof(tmp_buf));
if(mark ==1)
{
printf("test n is %d\n",n);
printf("++++++++++++++++sock_fd is %d\n",sock_fd);
n = read(sock_fd,tmp_buf,sizeof(tmp_buf));
printf("after re