PDA

View Full Version : read() doesn't read certain characters


Atomical
2005.09.12, 08:52 PM
I realize this isn't a game programming question but this is the only networking forum I know of. I'm working with http fetcher. http://http-fetcher.sourceforge.net/

The problem I'm running into is that when I choose to read an image from a website it only displays the first few readable characters. I don't want to clutter up the thread by posting the entire source but the source is available from the website.

Here's a snip of the read() line:


ret = read(sock, pageBuf + bytesRead, contentLength);

if(ret == -1)
{
close(sock);
free(pageBuf);
errorSource = ERRNO;
return -1;
}

bytesRead += ret;

if(ret > 0)



http fetcher does work with standard html. I just don't understand why it isn't reading the image.

Steven
2005.09.12, 09:25 PM
http://idevapps.com is this site's sister forum, geared more towards application development.

On second thought (edited away the first) are you treating the data as a C string at any point? There might be an embedded null in your data...

Atomical
2005.09.12, 10:13 PM
char c = pageBuf[strlen(pageBuf)+1];
char c = pageBuf[strlen(pageBuf)+2];

Both return null. So I don't think that's the case.

Steven
2005.09.12, 11:59 PM
I can imagine a binary file that has many nulls in a row (say you have a 35*35 black picture encoded as straight RGBA or whatever, that's quite a few 0 bytes in a row!)

Have you single-stepped through your code to ensure that you do actually call read more than once? I don't see a loop or anything in your snippet...

Atomical
2005.09.13, 09:31 AM
I ran it through the debugger it runs through it twice. I'm going to run some code to check if there is anything else in the array.

Atomical
2005.09.13, 09:53 AM
Alright that appears tobe the case. At least from my tests. I guess my problem was that I wasn't keeping track of the content length when writing to file. I was using strlen().