This is what I want.
I have a C program. It creates a series of binary files on the disk. The record (buffer) is about 1000 bytes per cycle. There can be maximum of 5000 cycles per file. So each file could be maximum of 5000 * 1000 bytes = 5000000 bytes.
Since this writing is done across a Ethernet, after each file is closing, it closes and locks up. I find that this is due to inability of trasfring that huge amount of data over the Ethernet because in my program there is a time-out period. The close() call exceeds the time-out. So it throws me out. That is a requirement I must have in the program.
So, now I try to flush the buffer every time the buffer is ready to be written. So I use the setvbuf() and
fflush() together. So I have something like this.
/*I am creating 10 files */
int i = 0;
for (int i = 0; i < 10; i++)
/*CReate a new file name here*/
fptr = fopen(filename);
while (i < 5000)
/*Create the buffer here, and fill it*/
/*set the buffer */
setvbuf( fptr, buf, _IOFBF, sizeof(buf));
/*flush it */
/*Ok. 500 cycles done. So close it */
I want to see when I do a dir or ls (in unix) the file is growing (changing the size). I do not see this hapenning. In fact I do not see even the file is created on the disk when I do a dir or ls when the loop is running. Only time I see the file created is when close() is called. However with ZERO file size. So the fflush() really did not work for me. I thought when I use fflush() along with setvbuf(), the data is trasferred immediately to the disk so that I can see the file is created and growing each cycle.
Can anyone out there throw some light into this?. I do not mind using any other method.