views:

56

answers:

0

I'm writing an iPhone App with a webserver in it. To handle a web request, I take the web request and write() to it the data that I want to send back.

When I try to download a moderately sized file (3-6MB) it works fine, but if I cancel the download halfway through, the app crashes and leaves no trace of an error. I'm thinking that the file descriptor becomes invalid halfway through the write, and causes the crash. I really don't know if this is what causes the crash, i'm just assuming.

I'm basing my webserver off of this example.

NSString *header = @"";
NSData *data = [NSData dataWithContentsOfFile:fullPath];
write (fd, [header UTF8String], [header length]);
write(fd, [data bytes], [data length]);
close(fd);

Does anyone know how to fix this? I was thinking about chunking the data and then writing each part, but I don't think it would help.