do loop in read file and send socket
Posted on 2009-12-24
What's wrong here?
hfile = CreateFileW(TheFile,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_SEQUENTIAL_SCAN,(HANDLE) NULL);
success = ReadFile(hfile,thebuf,sizeof(thebuf),&rlen,NULL);
while(success & rlen)
send(sock, (char *)thebuf, 1029, 0);
success = ReadFile(hfile, thebuf, sizeof(thebuf), &rlen, NULL);
and I start reading. thebuf is unsigned char. thebuf size is 1029.
If file is below 1029 bytes this code just works fine. If it's larger, if it's modulus of 1029, again (I THINK!!) it works, sometimes I see it works and some times not...But when it's not modulus of 1029, mostly it fails...
It fails means Apache don't receive file properly.