这是来自http服务器的数据接收功能代码,完美工作..但我想在这个功能中添加暂停和恢复..有人可以建议我怎么做吗?
注意:忽略变量声明。
int rest=0,size=0,count=0;
memset(buffer,'\0',sizeof(buffer));
do {
rc=read(sockfd,buffer,1500); //Reading from socket connection
if(rest==0)
{ /*Extracting Content length*/
data=strstr((char*)buffer,"Content-Length");
if(data!=NULL)
{
value=atoi((char*)data+15);data_rest=value;
rest=1;
}
}
if(count==0)
{ /*Extracting Header*/
content=strstr(buffer,"\r\n\r\n");
if(content!=NULL)
{
printf("FOUND Header END\n");
content=content+4;count=1;
/*copying DATA to the file which has same Extension*/
data_wrote=fwrite(content,sizeof(char),rc-(content-buffer),fp);
}
}
else
{
content=buffer;
/*copying DATA to the file which has same Extension*/
data_wrote=fwrite(content,sizeof(char),rc,fp);
}
size=size+rc;
total_wrote=total_wrote+data_wrote;
printf("Total size = %d\n",size);
memset(buffer,'\0',sizeof(buffer));
} while(rc>0); /*until end of file*/