SocketStream>>flush question

C. David Shaffer cdshaffer at acm.org
Mon Mar 8 06:27:47 UTC 2004


Oops, I shouldn't have hit "send" so quickly.  While I have your ear, 
could you write the equivalent of the following C code in Squeak using 
SocketStream (or even just a Socket):

if ((nbytes = read(socketFD, data, max)) == 0) {
  // handle close
} else if (nbytes < 0) {
  // handle error code in errno which sucks but at least it is there
} else {
  // handle data
}


My current guess looks something like this:

[char := socketStream next.
"handle data"] on: Error do: [ :ex |
  ex message = 'primitive failed'
    ifTrue: [socketStream isOtherEndConneced ifFalse: ["handle close"] 
ifTrue: ["handle error stored in socketStream socket socketError"]]
    ifFalse: [ex pass]]

I'd just like to see what people do...the existing clients don't seem to 
have much useful code in this regard.  I looked through HTTPSocket and 
Scamper's use of it and I don't find any useful error handling code.

David





More information about the Squeak-dev mailing list