Re: Detecting clsoed socket on OutputStream.Write



Knute Johnson wrote:
I don't know what causes the expected behavior to fail.

What causes this 'expected behaviour' to 'fail' is TCP asynchronous writing and buffering. If the write to the socket just goes into your local send buffer and the remote close hasn't already been detected, your write will succeed. It's only when you write *after* the remote close has been detected that you can get an IOException, and this in turn can only happen if there was data still pending to be written when the remote closure occurred.

In practice this means doing a number of writes to provoke the IOException: you can't rely on a single write doing it, i.e. you can't rely on the *next* write getting an IOException.
.



Relevant Pages

  • Re: Redirecting stdout of running program
    ... run whether it's writing to a terminal or a file, ... operations specific to that type later fail. ... Not that it's impossible to do "buffer buffering" with a terminal, but you won't see any output until some 4k or such of output has been generated, or line buffering with files calls than needed, as you wouldn't notice anyway). ... Josef Möllers (Pinguinpfleger bei FSC) ...
    (comp.os.linux.development.system)
  • Re: What happen if a shared memory is removed?
    ... and further shmget without IPC_CREAT will fail. ... isn't it the expected behaviour? ... the segment is marked for deletion, then, this is not possible to attach ...
    (comp.unix.programmer)
  • Re: couple of questions on streams
    ... > though it was different from line based buffering. ... modern times it is no longer easy to dot this, and you may assume that the ... No. IO can fail so strictly you should check the return from printfto see ... the buffer with setvbuf(). ...
    (comp.lang.c)
  • Re: [PHP] Re: $PHP_SELF
    ... > It's expected behaviour for a language feature to fail 10% of the time?! ... > Could you expand on your answer, ...
    (php.general)