splice lost data

From: xinglp
Date: Tue Apr 07 2009 - 15:49:15 EST


2.6.29.1 in VM

When recv data more than 8K (1024*8) bytes at once, data lost happen.
#define SPLICE_SIZE (1024*8)//when define SPLICE_SIZE bigger than (1024*8) data lost happen.
//This function is called when EPOLLIN on Socket
void RecvBySplice(int hFile,int Socket)
{
ssize_t SizeToRead;
ssize_t SizeRead;
ssize_t SizeLeft;
ssize_t SizeWrite;

while(ContentLength>0)//ContentLength is global
{
SizeToRead =SPLICE_SIZE>ContentLength?ContentLength:SPLICE_SIZE;

SizeRead =splice(Socket,NULL,Pipes[1],NULL,SizeToRead,SPLICE_F_NONBLOCK);//Pipes[] is global

if(SizeRead>0)
{
ContentLength-=SizeRead;

SizeLeft=SizeRead;

while(SizeLeft>0)
{
SizeWrite=splice(Pipes[0],NULL,hFile,NULL,SizeLeft,SPLICE_F_NONBLOCK);//Pipes[] is global

if(SizeWrite>0)
{
SizeLeft-=SizeWrite;
}
else if(EINTR==errno)
{
continue;
}
else
{
perror("splice");
return;
}
}

if(SizeRead<SizeToRead)
{
return;//No more data in socket buf
}
}
else
{
if(0==SizeRead)
{
perror("peer close");
return;
}
else
{
if(EAGAIN==errno)
{
return;
}
else if(EINTR==errno)
{
continue;
}
else
{
perror("splice");
return;
}
}
}
}
}