[squeak-dev] Re: advice on efficient socket programming sought
Paolo Bonzini
bonzini at gnu.org
Sat Jul 19 19:13:48 UTC 2008
> My read pattern will be:
> - read one to four bytes
> - read a chunk of up to 8k bytes, the number of bytes is encoded in
> the bytes read before, these chunks can be either binary or text,
> again this depends on the bytes read above
> - repeat
For reading, you can proceed unbuffered -- read four bytes, parse them
to find the length, read the rest of the chunk at the end of the
collection, and fill in the beginning of the collection with what's left
of the four bytes.
> My write pattern will be similar. It could be made into bulk writes of up to 8k.
Also, the best here would be to have access to writev. I don't know if
Squeak's sockets support it but I doubt.
> If is it preferable to
> run #ascii and convert the integer protocol constants to Characters or
> run #binary and send #asString to the resulting ByteArray?
If you need what you read as a String, run #ascii. Otherwise, run
#binary and write your own method to parse the Integers for the 1-4
bytes in the prolog. Sometimes with this kind of stuff the temptation
to do changeClassTo: String is very strong...
Paolo
More information about the Squeak-dev
mailing list
|