[quote]Look like you have something to fix, Blah.
From the networking engineer who does the libraries…
"Do you mean DatagramSocket.send()? or do you mean Socket.getOutputStream().write()?
Either way, the data is buffered in the OS and the call is returned as soon as the data is written to the buffer."
To answer your hypothetical, you DON’T necessarily get an exception for any given packet, you get an exception when the OS has registered a failure. That may not be registered until multiple packets have been queued up.
[/quote]
Cool, thanks. When endolf originally asked, I had to go away and think about it and try and work out what was actually happening. I had been taught a long time ago precisely what this engineer has stated, but spurred on by endolf’s question to really think about this I’m now a little disturbed.
(N.B. in the article, I was attempting to illustrate some of the theoretical differences between IO and NIO; because of variance from JVM to JVM anything that’s not mandated by Sun e.g. within the API docs is not guaranteed to hold anywhere, though it may be true somewhere. I’ve recently been revising the article to add more examples of such theoretical differences, and also to make more clear that I’m only highlighting how your VM’s may be expected to work; you can never be sure which JVM’s will observe which differences. I’ll be glad to also make clear the current state of Sun’s VM’s on this issue…)
Anyway… semantically within java, can you get an exception except inside the method call to trigger the send (I suggest let’s just concentrate on the write() method of the output stream for now, since it’s the most commonly used…)?
I’m sure I’ve got the wrong end of the stick here, but…The response you’ve been given makes it sound like there are exceptions that will only be thrown if you make a SUBSEQUENT call to the same method - simply because they were waiting in limbo for the opportunity to happen (i.e. even if the OS signalled java, java has moved on and it’s now illegal for java to throw the exception)?
Another thing that has me confused now is the observed behaviour that java can (and does!) hang indefinitely on attempts to synchronously send a few hundred bytes of data until the receiver actually starts reading it from the receiver’s local buffers. Just guessing here, perhaps this observation is due to java peeking at the TCP state, observing that although it’s dumped the data into the send buffer, the remote host is not reading it, and blocking anyway?
The most recent examples I’ve seen of this are simple HTTP communication - if you set up a simple IO-based HTTP Server, listen to a serversocket, accept the incoming connection, but don’t make the read() call on the socket, then the sender (in a different class, connecting to the serversocket, and calling write()) blocks indefinitely. I haven’t done this for quite a long time (I use NIO exclusively these days :)), so if this differs from other people’s experience I’ll have to try and dig out old code and see what I’m misremembering. Assuming my memory’s correct, it sounds like my interpretation of this symptom has been wrong all along? 