Page 1 of 1

string data format and other questions

PostPosted: Mon Oct 22, 2007 6:00 am
by mrstandridge
Hello, I'm very new to pocketc and have a few questions. The example network.pc uses the expression "sockrecv(s, &index, "s", 1);" to download an entire text file into a string. While the documentation states that sockrecv uses the same format as dbwritex, there is only a mention of "sz" and "s#" in the documentation for dbwritex. I tried using "s" in fileread but no data is being entered into the string and fileread returns 0. fileread should return the quantity of data read, right? Does fileread support "s"? How should I go about reading a text file, into a char array? I would also like to download arbitrary data like jpg or zip and write to a file. Should I just pass sockrecv a pointer to a fileid if I'm only using HTTP/1.0 and don't have to worry about chunked data?

Re: string data format and other questions

PostPosted: Wed Oct 24, 2007 4:19 pm
by dewey
The single "s" is shorthand for "sz". fileread does support "s". There was a bug in fileread (or the OrbC equivalent File.read) long ago that would cause something similar to this. I'll have to test this to see if it is still broken. Also, the max size of a string that can be read from a file is 512 bytes. This limit does not exist for sockets, which is limited only by available memory.

You can't pass a fileid to sockrecv, since it doesn't support writing to files directly. You will need to download into a buffer (char[]) and then write that data to the file.

Re: string data format and other questions

PostPosted: Thu Oct 25, 2007 4:05 am
by dewey
Yes, this was a bug in File.read that was fixed long ago. However, the same flaw was not fixed in fileread. However, while investigating this, I found another bug which affects both File.read (OrbC) and fileread (legacy PocketC). I will spin up a new build in the next few days with a fix.

Re: string data format and other questions

PostPosted: Sat Oct 27, 2007 4:26 am
by mrstandridge
Thanks a bunch for the informative reply!