how to read in large amount of data in C?

D

dreamvigile

Hi,
when recv is used in C to download large (several megabyte) textfiles
from an FTP data port, there tend to be discrepancies in the amount of
data downloaded (too much, too little...) One of the problems is, an
FTP data port tends to send all the data at once, then immediately
hang up. What is a good procedure for obtaining the data? my basic
strategy is:

check if recv returns -1
if so, check if errno == EAGAIN (the socket is nonblocking)
if so, return to step 1 after a few fractions of a millisecond
if not, assume file download is complete
if not, read as much data as possible without blocking

One of the things that would help would be, on the last recv where you
get that last bit of data and the ftp data port closes the connection,
what does recv return? -1 because the connection snaps shut, or a
positive number because it read data?
Thanks very much in advance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top